mysql 查询日周月每天数据

SELECT d.index as days,d.date as time,COUNT(a.id) as count_num
FROM(
SELECT @a :=@a + 1 as `index`, DATE(ADDDATE(CURRENT_DATE, INTERVAL @a DAY)) AS `date`
FROM mysql.help_topic,(SELECT @a := 0) temp
WHERE @a < 6 - WEEKDAY(CURRENT_DATE)
UNION
SELECT @s :=@s - 1 as `index`, DATE(DATE_SUB(CURRENT_DATE, INTERVAL @s DAY)) AS `date`
FROM mysql.help_topic,(SELECT @s := WEEKDAY(CURRENT_DATE) + 1) temp
WHERE @s > 0
ORDER BY `date` ) as d
left join travel_active a
on d.date=date_format(a.create_time,'%Y-%m-%d')


select create_time,COUNT(id) FROM travel_active where YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now())
GROUP BY date_format(create_time,'%Y-%m-%d')


select * from travel_active where yearweek(date_format(create_time,'%Y-%m-%d') = YEARWEEK(now())


select DAYOFWEEK(now()) weekDay

SELECT yearweek(date_format(now(),'%Y-%m-%d') = YEARWEEK(now())

select
        sum(case DAYOFWEEK(create_time) when '1' then 1 else 0 end) as '7',
        sum(case DAYOFWEEK(create_time) when '2' then 1 else 0 end) as '1',
        sum(case DAYOFWEEK(create_time) when '3' then 1 else 0 end) as '2',
        sum(case DAYOFWEEK(create_time) when '4' then 1 else 0 end) as '3',
        sum(case DAYOFWEEK(create_time) when '5' then 1 else 0 end) as '4',
        sum(case DAYOFWEEK(create_time) when '6' then 1 else 0 end) as '5',
        sum(case DAYOFWEEK(create_time) when '7' then 1 else 0 end) as '6'
        from travel_active
				where YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now())



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值