Group By First Query in MySql
所以我问了上面的问题并得到了很好的回应
但是如何在homematchingid !=0
和awaymatchingid !=0
的位置添加?
我已经尝试了以下方法,但都无法正常工作。
SELECT MIN(`Date`) AS `Date`, MIN(`Time`) AS `Time`,
`HomeMatchingId`,`AwayMatchingId`,`RunningStatus`
FROM `20121208`
where `HomeMatchingId`!= 0,`AwayMatchingId`!= 0
GROUP BY `HomeMatchingId`,`AwayMatchingId`,`RunningStatus`
HAVING `RunningStatus`= 1
和
SELECT MIN(`Date`) AS `Date`,MIN(`Time`) AS `Time`,
`HomeMatchingId`,`AwayMatchingId`,`RunningStatus`
FROM `20121208`
GROUP BY `HomeMatchingId`,`AwayMatchingId`,`RunningStatus`
HAVING `RunningStatus`=1,`HomeMatchingId`!=0,`AwayMatchingId`!=0);
最佳答案
您需要使用诸如AND或OR之类的逻辑运算符替换where子句中的逗号。
SELECT MIN(`Date`) AS `Date`, MIN(`Time`) AS `Time`,
`HomeMatchingId`,`AwayMatchingId`,`RunningStatus`
FROM `20121208`
where `HomeMatchingId`!= 0 AND `AwayMatchingId`!= 0
GROUP BY `HomeMatchingId`,`AwayMatchingId`,`RunningStatus`
HAVING `RunningStatus`= 1