Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有sum=0的Mysql返回0行_Mysql - Fatal编程技术网

具有sum=0的Mysql返回0行

具有sum=0的Mysql返回0行,mysql,Mysql,我还有一个查询,连接两个表用户信息表和他们的时间表表 我试着找出谁没有2016618的时间表 我使用了SUM,但它返回0行 有人知道问题出在哪里吗?我在本地服务器上进行了尝试,@Jhecht是正确的,CONCAT返回字符串,您必须在2016618上添加引号 所以你的代码必须是 SELECT user.id, CONCAT(lastname, firstname), year, month, date FROM user LEFT JOIN adoption ON user.id = adopti

我还有一个查询,连接两个表用户信息表和他们的时间表表

我试着找出谁没有2016618的时间表

我使用了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

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

我刚刚尝试了一些你的结果,也许对你有帮助

 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
结果:

CREATE TABLE Table1
    (`id` int, `name` varchar(4), `year` varchar(4), `month` varchar(4), `date` varchar(4))
;

INSERT INTO Table1
    (`id`, `name`, `year`, `month`, `date`)
VALUES
    (16, 'Mr.A', '2016', '6', '25'),
    (17, 'Mr.B', '2016', '6', '18'),
    (18, 'Mr.C', NULL, NULL, NULL),
    (19, 'Mr.D', NULL, NULL, NULL)
;

SELECT * FROM Table1
GROUP BY id
HAVING SUM(if(CONCAT(year,month,date) = 2016618, 1, 0)) = 0

尝试将2016618用引号括起来,因为我相信concat会返回一个字符串。尝试添加
COUNT(*)
作为结果列。我打赌id 17有不止一行。相反,您应该只写
年=2016,月=6,日期=18
。我是说,你不能计算日期。2016年4月1日+2020年7月19日意味着什么?(不包括四月傻瓜)拥有年份=2016年。。。这将返回当天有日程安排的人,但我需要返回未使用正确日期数据类型存储日期的人。我刚刚发现问题是C&D先生的年、月、日期列为空,因此sum不会返回0,但我仍在尝试如何编写此查询
| id | name | year | month | date | 
+----+------+------+-------+------+
| 16 | Mr.A | 2016 | 6     | 25   | 
| 18 | Mr.C | null | null  | null | 
| 19 | Mr.D | null | null  | null |