|
恩, 楼上的思路也挺好, 不过用临时表来做有点太费事了,
select DEPT,ITEM,Max(QTY) as QTY
from Table
group by DEPT,ITEM
UNION
select DEPT,ITEM,Max(QTY) as QTY
from Table T1
Where exists(select null from table T2 where T1.dept=T2.dept and T2.qty > T1.qty)
group by DEPT,ITEM
如果还要求第三大第四大这个方法就不太适用了
上面的做法是错地!!!!!!!!!!!!!!!!!!!!!!!!!!![/COLOR] |
|