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())
mysql 查询日周月每天数据
最新推荐文章于 2024-11-08 16:02:03 发布