mysql过滤SELECT查询结果。

时间:2018-06-27 11:24:22

标签: mysql

我有以下查询。

step2

然后我想过滤掉NumResults,因此该表仅显示NumResults = 1的结果。

1 个答案:

答案 0 :(得分:2)

使用HAVING子句过滤聚合函数的结果(在您的情况下为COUNT

SELECT COUNT(id) AS NumResults, race_date AS RaceDate, race_time AS RaceTime
FROM results 
WHere jockeys_claim = 10
GROUP BY race_date, race_time
HAVING COUNT(id) = 1
ORDER BY race_date DESC, race_time ASC