【发布时间】:2015-01-31 07:13:20
【问题描述】:
我想统计今天、昨天、上周、上个月的客户城市。
我想要这样的结果
city today yesterday lastweek lastmnth
1 23 2 12 12
我的表结构如下所示
客户
c_id city_id c_name currentdate
1 1 Rama 2015-01-30 09:43:17
2 1 kavitha 2015-04-30 09:43:17
城市
city_id city_name
1 hyd
2 Wgl
我用下面的方法试过了。
select c.c_city, (select count(cr_id) as lastmonth from customer
where currentdate > DATE(NOW() - INTERVAL 30 DAY) )) from customers as c
left join cities as ci on c.city_id = ci.city_id group by c.city_id
【问题讨论】: