gpt4 book ai didi

Mysql 总和 = 0 返回 0 行

转载 作者:行者123 更新时间:2023-11-29 20:56:16 25 4
gpt4 key购买 nike

SELECT user.id, CONCAT(lastname, firstname), year, month, date FROM user
LEFT JOIN adoption ON user.id = adoption.adopter
GROUP BY user.id

id CONCAT(lastname, firstname) year month date
16 Mr.A 2016 6 25
17 Mr.B 2016 6 18
18 Mr.C NULL NULL NULL
19 Mr.D NULL NULL NULL

//after, I add this, should return Mr.A, C, D
HAVING SUM(CONCAT(year,month,date)= 2016618 ) = 0

我有一个查询 LEFT JOIN 两个表用户信息表及其日程表

我尝试找出谁在 2016618 没有安排

我使用了 HAVING SUM,但它返回 0 行

有人知道问题出在哪里吗?

最佳答案

我在本地服务器上尝试,@Jhecht 是对的,CONCAT 返回字符串,您必须在 2016618 上添加引号

所以你的代码必须是

 SELECT user.id, CONCAT(lastname, firstname), year, month, date FROM user
LEFT JOIN adoption ON user.id = adoption.adopter
GROUP BY user.id
HAVING SUM(CONCAT(year,month,date) = '2016618') = 0

关于Mysql 总和 = 0 返回 0 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37604876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com