-1

所以我有一大堆选票进入投票系统。我想显示我在任何一天有多少票。但我也想然后,显示每天的票数并吐出他们在哪一天投票,即 24k 票在 05/06/12,27k 票在 06/06/12

SELECT count(*) AS count
FROM results 
GROUP BY DAY(datesubmitted), YEAR(datesubmitted), MONTH(datesubmitted) 
ORDER  BY DAY(datesubmitted) DESC, YEAR(datesubmitted) DESC, MONTH(datesubmitted) DESC

是我的查询,我尝试添加类似

DAY(FROM_UNIXTIME(datesubmitted)) 作为 order_day

但这只是抛出一个我觉得有趣的空值,因为我希望查询失败,因为没有任何外部。

4

3 回答 3

1

你为什么不干脆GROUP BY datesubmitted DESC?此外,如果它遵循与 GROUP BY 相同的标准,则无需 ORDER BY。

于 2012-06-06T01:15:46.717 回答
0

特定日期的投票数:

SELECT COUNT(*) AS total
FROM results 
WHERE datesubmitted BETWEEN @dateMin AND @dateMax

每一天的票数:

SELECT COUNT(*) AS total, DATE(datesubmitted) AS day
FROM results 
GROUP BY DATE(datesubmitted)
ORDER BY DATE(datesubmitted) DESC

再次更新

于 2012-06-05T23:53:05.957 回答
-1

所以刚刚看到一个新的答案,但对我来说,我是如何让它工作的:

SELECT count(*) AS count, DAY(datesubmitted) AS newday, 
YEAR(datesubmitted) as newyear ,MONTH(datesubmitted) as newmonth
FROM results 
GROUP BY DAY(datesubmitted), YEAR(datesubmitted), MONTH(datesubmitted) 
ORDER  BY  YEAR(datesubmitted) DESC, MONTH(datesubmitted) DESC, DAY(datesubmitted) DESC

这样我就可以正确地获得年、月和日的正确排序,并且它还显示日期。我可以连接它们,但那是另一天。

于 2012-06-05T23:56:14.997 回答