有一个MYSQL表bookings
包含booking_id
,booking_code
,timestamp
。
我想显示一天内的预订数量。
此查询,
SELECT `timestamp`, count(`booking_id`)
FROM `bookings`
group by `booking_id`
order by `timestamp` desc
给出如下结果
timestamp count(`booking_id`)
2016-02-25 20:49:42 1
2016-02-25 20:42:13 1
2016-02-25 14:00:24 1
2016-02-25 12:51:21 1
2016-02-24 19:44:29 1
2016-02-24 19:08:38 1
我理解为什么结果是这样的,bcoz考虑了时间和时间[时间戳]。
但我需要的是像这样的结果
timestamp count(`booking_id`)
2016-02-25 4
2016-02-24 2
答案 0 :(得分:0)
SELECT DATE(timestamp) AS day,
COUNT(*) AS bookingcount
FROM bookings
GROUP BY DATE(timestamp)
ORDER BY day desc