数据都在一张表中:
table(id,operator,dealtime......)
id:自增长主键
opeartor:操作员代号
dealtime:操作时间
自己些了个只能查单个操作员最近15天的数据。我最好全部一次性查出。给思路也行。
select t2.time,IFNULL(t1.count,0) from (select date(lc.dealtime)value,count(lc.id)count from table lc
where operator='gg'
and date_sub(now(), INTERVAL 15 DAY) <= date(lc.dealtime) group by value)t1
right join (
select date(date_sub(now(), INTERVAL 14 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 13 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 12 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 11 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 10 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 9 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 8 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 6 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 7 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 5 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 4 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 3 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 2 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 1 DAY)) time from DUAL UNION
select date(date_sub(now(), INTERVAL 0 DAY)) time from DUAL
)t2 on t2.time=t1.value