V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
omg21
V2EX  ›  Python

请教一个 sql 语句

  •  1
     
  •   omg21 · 2017-05-26 11:19:54 +08:00 · 2270 次点击
    这是一个创建于 2527 天前的主题,其中的信息可能已经有所发展或是发生改变。

    A 表是主表,运行时如果有问题就把 A 表出问题的记录 ID 保存到 log 表中,等到全都运行完了后,再从 log 表中取出出问题的 ID 重新执行。 就是这最后一步的 sql 语句不会写,从 log 表中取出 ID 号,然后再从 A 表中取出相应的 ID 执行。

    10 条回复    2017-05-26 17:01:02 +08:00
    liprais
        1
    liprais  
       2017-05-26 11:33:35 +08:00
    select id from A where id in ( select id from log )
    geelaw
        2
    geelaw  
       2017-05-26 11:34:27 +08:00
    或者你可以 join
    littleylv
        3
    littleylv  
       2017-05-26 11:42:53 +08:00
    为什么这么麻烦要 log 表。
    A 表多一个字段记录运行状态,如果运行有问题,标记一下这个字段。
    等到全都运行完了后,取 A 表中运行状态字段是你标记的值的记录就行了。
    fxxkgw
        4
    fxxkgw  
       2017-05-26 12:31:25 +08:00
    select a.id from log l left join A a on l.A_id=a.id where l.id=xxxx
    omg21
        5
    omg21  
    OP
       2017-05-26 13:31:13 +08:00
    @littleylv 嗯,之前就是这么想的,后来要求保存错误原因,才单设一个 log 表
    omg21
        6
    omg21  
    OP
       2017-05-26 13:31:43 +08:00
    @liprais
    @fxxkgw
    OK,搞定了,谢谢
    slixurd
        7
    slixurd  
       2017-05-26 13:40:05 +08:00
    不要用 IN,不要用 IN,不要用 IN....
    尤其是带子查询的 IN,DEPENDENT SUBQUERY 的性能非常有问题
    4 楼的 JOIN 更好一点....
    Ironsongming
        8
    Ironsongming  
       2017-05-26 14:43:49 +08:00
    @littleylv bingo
    Ironsongming
        9
    Ironsongming  
       2017-05-26 14:46:10 +08:00
    @omg21 你这是数据类的系统么?如果不是,还不如直接在代码层面做错误日志收集呢。如果是,为什么不对全局做操作日志呢?
    robinshi2010
        10
    robinshi2010  
       2017-05-26 17:01:02 +08:00
    感觉 3 楼说的有道理啊。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1026 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 61ms · UTC 23:01 · PVG 07:01 · LAX 16:01 · JFK 19:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.