V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
sherlockwhite
V2EX  ›  问与答

MySQL 一个很奇怪的问题, union 结果的时候字段颠倒了

  •  
  •   sherlockwhite · 2020-03-14 18:42:02 +08:00 · 838 次点击
    这是一个创建于 1506 天前的主题,其中的信息可能已经有所发展或是发生改变。

    image.png image.png

    情况是几个字段 union,然后查出来一条结果,但是这一条结果的 add 和 reduce 值颠倒了。单独把 union 的那一条拿出来执行是正常的。

    image.png image.png

    9 条回复    2020-03-16 09:56:06 +08:00
    sherlockwhite
        1
    sherlockwhite  
    OP
       2020-03-14 18:44:28 +08:00
    有大佬知道是什么情况吗
    singerll
        2
    singerll  
       2020-03-14 18:46:53 +08:00 via Android
    不一定是 mysql 的问题吧,也可能是工具。。。换命令行试试?
    sherlockwhite
        3
    sherlockwhite  
    OP
       2020-03-15 00:17:06 +08:00
    @singerll #2 不是的,我代码里跑出来出问题我才去找问题的。用的是 MySQL workbeach
    msg7086
        4
    msg7086  
       2020-03-15 03:47:00 +08:00
    多试试几个版本和分支的 MySQL 看看?
    有时候会出现某些特定版本有 Bug 的情况。
    changwei
        5
    changwei  
       2020-03-15 03:53:04 +08:00 via Android
    為什麼要寫 0 as reduce 這個字段沒看懂
    sherlockwhite
        6
    sherlockwhite  
    OP
       2020-03-15 11:58:36 +08:00 via Android
    @changwei union 补字段
    sherlockwhite
        7
    sherlockwhite  
    OP
       2020-03-16 09:55:23 +08:00
    很奇怪的是,我把图一的两条换过来就正常了。
    sherlockwhite
        8
    sherlockwhite  
    OP
       2020-03-16 09:55:33 +08:00
    不知道是什么原理。
    sherlockwhite
        9
    sherlockwhite  
    OP
       2020-03-16 09:56:06 +08:00
    0 as reduce,money as add => money as add,0 as reduce
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5152 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 03:52 · PVG 11:52 · LAX 20:52 · JFK 23:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.