dtime 日期,DATA分数,kkkk为楼主认为的基本表
select dtime,max(data)as data,1 as mm from kkkk group by dtime
union
select m.dtime,max(m.data)as data,2 from(select s.* ,case when s.data=m.data then 1 else 0 end tt from kkkk s left join (select dtime,max(data)as data from kkkk group by dtime ) m on s.dtime=m.dtime and s.data=m.data)m where isnull(m.tt,0)=0
group by m.dtime
union
select m.dtime,max(m.data)as data,3 from (select s.* case when s.data=m.data then 1 else 0 end tt from kkkk s left join (select dtime,max(data)as data from kkkk group by dtime
union
select m.dtime,max(m.data) as data from (select s.*,case when s.data=m.data then 1 else 0 end tt from kkkk s left join (select dtime,max(data) as data from kkkk group by dtime)m on s.dtime=m.dtime and s.data=m.data
where isnull(m.tt,0)=0
group by m.dtime)m
on s.dtime=m.dtime and s.data=m.data) m
where isnull(m.tt,0)=0
group by m.dtime