select date_format(cu.created_at, '%Y/%m/%d') as 日付,
count(cu.user_id) as 利用者数
from coupon_used as cu
where cu.code in ("2019", "2018")
and cu.created_at >= "2018-01-01 00:00:00"
and cu.created_at < "2020-01-01 00:00:00"
group by date_format(cu.created_at, '%Y/%m/%d');
date_format
便利
ちなみに、asで定義したdate_formatはgroup by
で使用できた。
select date_format(cu.created_at, '%Y/%m/%d') as 日付,
count(cu.user_id) as 利用者数
from coupon_used as cu
where cu.code in ("2019", "2018")
and cu.created_at >= "2018-01-01 00:00:00"
and cu.created_at < "2020-01-01 00:00:00"
group by 日付
group by 日付
面白い
変数定義みたいにindex保存されてるのかな
SqlでLoopとかも書いてみたいけど、その域になったらクエリビルダ使用したほうがいいな笑