所以我有一大堆投票进入投票系统。我想显示我在任何一天有多少票。但我当时也希望显示每天的投票数量并吐出他们被投票的那天,即2012年6月5日的24k票,2012年6月6日的27k票。
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
但是这只会抛出一个null,我发现它很有趣,因为我希望查询失败,因为没有任何outers。
答案 0 :(得分:1)
为什么不简单GROUP BY datesubmitted DESC
?此外,如果它遵循与GROUP BY相同的标准,则无需ORDER BY。
答案 1 :(得分: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
再次更新
答案 2 :(得分:-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
通过这种方式,我可以正确地获得正确的年,月,日订购,并显示日期。我可以把它们连在一起,但那是另一天。