将两个条件与不同的MySQL组合在一起

时间:2018-03-27 16:16:01

标签: mysql group-by count

我可以用这两个条件进行一次查询吗?如果是的话,我应该挖哪个方式?

SELECT c.ID, c.DateEnd FROM conference c WHERE DateEnd = DATE_ADD(CURDATE(),INTERVAL 1 DAY)

SELECT a.ID, a.IDConf FROM application a GROUP BY a.IDConf HAVING COUNT(a.IDConf) >= 2

2 个答案:

答案 0 :(得分:0)

您可以使用左连接。试试这个:

SELECT c.ID, a.ID a_ID, c.DateEnd 
FROM conference c LEFT JOIN application a 
ON c.ID=a.IDConf
WHERE DateEnd=DATE(DATE_ADD(CURDATE(),INTERVAL 1 DAY))
GROUP BY c.ID, a.ID 
HAVING COUNT(a.IDConf)>=2;

有关使用联接的见解,请参阅MySQL Join Made Easy

答案 1 :(得分:0)

如果您只想加入/public的结果,可以在子选择中使用内部联接

HAVING COUNT(a.IDConf) >= 2