0

我有一个“订单”表,其中有一个时间戳字段,因此数据如下所示:

id | createdate          | customerid 
1  | 2013-10-03 09:35:20 |   5
2  | 2013-10-03 09:35:20 |   9
3  | 2013-10-04 15:00:20 |   5
4  | 2013-10-05 12:15:20 |   5

因此,我需要从这张表中创建一个 html 表,在顶部显示周一至周六,在侧面显示小时,如下所示:

Hours      |  Monday  | Tuesday  | Wednesday  |  Thursday  |  Friday  | Saturday
9:30 - 10  |    0     |    0     |     0      |     2      |    0     |    0
10-11      |    0     |    0     |     0      |     0      |    0     |    0
11-12      |    0     |    0     |     0      |     0      |    1     |    0  

所以现在我到目前为止是这样的:

SELECT DATE_FORMAT( createdate,  '%m/%d/%Y' ) AS createdate
, DATE_FORMAT( createdate,  '%H' ) AS createhour, COUNT( * ) AS totals
FROM  orders
WHERE createdate >= CURDATE( ) - INTERVAL DAYOFWEEK( CURDATE( ) ) +6
DAY AND createdate < CURDATE( ) - INTERVAL DAYOFWEEK( CURDATE( ) ) -1
DAY GROUP BY DATE_FORMAT( createdate,  '%m/%d/%Y' ) , DATE_FORMAT( createdate,  '%H' )

这会返回数据但不是我需要的格式,有没有办法在 mysql 中做到这一点?或者它是否涉及一些带有数组的 php 工作?

4

0 回答 0