额外的查询参数不起作用

时间:2014-01-23 12:53:02

标签: mysql

Group By First Query in MySql

所以我问上面的内容并得到了很好的回复

但如何添加homematchingid !=0awaymatchingid !=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);

3 个答案:

答案 0 :(得分:1)

您需要使用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

答案 1 :(得分:0)

尝试<>而不是!=

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

SELECT MIN(`Date`) AS `Date`,MIN(`Time`) AS `Time`,
    `HomeMatchingId`,`AwayMatchingId`,`RunningStatus`
FROM `20121208`
GROUP BY `HomeMatchingId`,`AwayMatchingId`,`RunningStatus` 
HAVING `RunningStatus`=1 AND `HomeMatchingId`<>0 AND `AwayMatchingId`<>0;

答案 2 :(得分:0)

试试这个

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

SELECT MIN(`Date`) AS `Date`,MIN(`Time`) AS `Time`,
    `HomeMatchingId`,`AwayMatchingId`,`RunningStatus`
FROM `20121208`
GROUP BY `HomeMatchingId`,`AwayMatchingId`,`RunningStatus` 
HAVING `RunningStatus`=1 AND `HomeMatchingId`<>0 AND `AwayMatchingId`<>0;