最老:select * from ( select no,date,sum(num) as num from tablename group by no,date ) as x where date=( select min(date) from ( select no,date from tablename group by no,date ) as y where y.no=x.no )次老比较麻烦,有可能不存在次老
select NO,DATE,sum(NUM) num from 表 tem where [DATE]=(select min([DATE]) from 表 where [NO]=tem.[NO]) group by NO,DATE
1.最老select * from T a where DATE = (select min(date) from T where no = a.no)2.次老 select * from T a where DATE = (select min(date) from T b where b.no = a.no and b.date > (select min(date) from T where b.no = no ) )
次老:select NO,DATE,sum(NUM) num from 表 tem where [DATE]<>(select min([DATE]) from 表 where [NO]=tem.[NO]) and [DATE] in (select top 2 [DATE] from 表 where [NO]=tem.[NO] order by [DATE]) group by NO,DATE
1.最老select no,DATE,sum(NUM) from T a where DATE = (select min(date) from T where no = a.no) group by no,DATE2.次老 select no,DATE,sum(NUM) from T a where DATE = (select min(date) from T b where b.no = a.no and b.date > (select min(date) from T where b.no = no ) ) group by no,DATE
2.次老 select no,DATE,sum(NUM) from T a where DATE = (select min(date) from T b where no = a.no and date > (select min(date) from T where no = b.no ) ) group by no,DATE
select no,date,sum(num) as num
from tablename
group by no,date
) as x
where date=(
select min(date) from (
select no,date
from tablename
group by no,date
) as y
where y.no=x.no
)次老比较麻烦,有可能不存在次老
group by NO,DATE
from T a
where DATE = (select min(date) from T where no = a.no)2.次老
select *
from T a
where DATE = (select min(date)
from T b
where b.no = a.no
and b.date > (select min(date)
from T
where b.no = no
)
)
group by NO,DATE
from T a
where DATE = (select min(date) from T where no = a.no)
group by no,DATE2.次老
select no,DATE,sum(NUM)
from T a
where DATE = (select min(date)
from T b
where b.no = a.no
and b.date > (select min(date)
from T
where b.no = no
)
)
group by no,DATE
select no,DATE,sum(NUM)
from T a
where DATE = (select min(date)
from T b
where no = a.no
and date > (select min(date)
from T
where no = b.no
)
)
group by no,DATE