sql数据库双重排序
来源:百度知道 编辑:UC知道 时间:2024/05/26 14:34:15
id itype num
1 a 80
2 a 90
3 b 80
4 b 70
表如上面所示:
要求搜索itype中的num为最大一项。结果如下:
id itype num
2 a 90
3 b 80
1 a 80
2 a 90
3 b 80
4 b 70
表如上面所示:
要求搜索itype中的num为最大一项。结果如下:
id itype num
2 a 90
3 b 80
select *
from tab
where num in (select max(num) from tab group by itype)
order by id desc,itype desc,num desc
是不是要这种效果?
select ID,IType,Num from TableName A
where not exists(select 1 from TableName
where Itype = A.Itype and Num > A.NUm)
select * from TableName A where A.num >= all(select num from TableName where itype = A.itype)