问题一:1、$array数组如下:
array (size=7)
1 => string '2018-09-21' (length=10)
2 => string '2018-09-22' (length=10)
3 => string '2018-09-23' (length=10)
4 => string '2018-09-24' (length=10)
5 => string '2018-09-25' (length=10)
6 => string '2018-09-26' (length=10)
7 => string '2018-09-27' (length=10)
2、$list数组如下:
array (size=3)
0 =>
array (size=2)
'riqi' => string '2018-09-21' (length=10)
'count' => int 2
1 =>
array (size=2)
'riqi' => string '2018-09-26' (length=10)
'count' => int 2
2 =>
array (size=2)
'riqi' => string '2018-09-27' (length=10)
'count' => int 3
求助:如何php实现以下效果
array (size=3)
0 =>
array (size=2)
'riqi' => string '2018-09-21' (length=10)
'count' => int 2
1 =>
array (size=2)
'riqi' => string '2018-09-22' (length=10)
'count' => int 0
2 =>
array (size=2)
'riqi' => string '2018-09-23' (length=10)
'count' => int 0
3 =>
array (size=2)
'riqi' => string '2018-09-24' (length=10)
'count' => int 0
4 =>
array (size=2)
'riqi' => string '2018-09-25' (length=10)
'count' => int 0
5 =>
array (size=2)
'riqi' => string '2018-09-26' (length=10)
'count' => int 2
6 =>
array (size=2)
'riqi' => string '2018-09-27' (length=10)
'count' => int 3
问题二:现有sql如下:
select FROM_UNIXTIME(addtime,'%Y-%m-%d') as riqi, count(1) as count from order where FROM_UNIXTIME(addtime,'%Y-%m-%d') >= now() - interval 7 day group by FROM_UNIXTIME(addtime,'%Y-%m-%d')
如何能通过一句sql实现以下效果
array (size=3)
0 =>
array (size=2)
'riqi' => string '2018-09-21' (length=10)
'count' => int 2
1 =>
array (size=2)
'riqi' => string '2018-09-22' (length=10)
'count' => int 0
2 =>
array (size=2)
'riqi' => string '2018-09-23' (length=10)
'count' => int 0
3 =>
array (size=2)
'riqi' => string '2018-09-24' (length=10)
'count' => int 0
4 =>
array (size=2)
'riqi' => string '2018-09-25' (length=10)
'count' => int 0
5 =>
array (size=2)
'riqi' => string '2018-09-26' (length=10)
'count' => int 2
6 =>
array (size=2)
'riqi' => string '2018-09-27' (length=10)
'count' => int 3
4 回答
凤凰求蛊
TA贡献1825条经验 获得超4个赞
SELECT FROM_UNIXTIME(addtime,'%Y-%m-%d') as riqi,count(*) from order GROUP BY riqi ORDER BY riqi LIMIT 7
应该是你要的结果
12345678_0001
TA贡献1802条经验 获得超5个赞
用to_days(now()) - to_days(addtime)<= 7来查取近7天的数据,然后用date方法将时间只保留到天数。再对查到的数据,根据时间进行分组,再count(订单),得到就是每天对应的订单数了。
如果要把订单数为0 的天数也展示出来,就写个日期的循环,判断每天的日期是否在查询结果里有对应的记录,有就直接取,没有就是0.
效果图:
- 4 回答
- 0 关注
- 1321 浏览
添加回答
举报
0/150
提交
取消