使用MYSQL显示每天预订的数量

时间:2016-02-25 21:00:24

标签: mysql

有一个MYSQL表bookings包含booking_idbooking_codetimestamp

我想显示一天内的预订数量。

此查询,

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

1 个答案:

答案 0 :(得分:0)

很酷,我明白了!

SELECT DATE(timestamp) AS day,
        COUNT(*) AS bookingcount
 FROM   bookings
 GROUP BY DATE(timestamp)
 ORDER BY day desc