求一SQL语句(按两个条件查询SQL)
有一表AA ,
自动编号ID 分数num
要按分数从高到低排列,当分数相同时按ID顺序排列,
这样的SQL要怎么写啊,谢谢高手,呵呵!
------解决方案--------------------select * from AA order by num desc, id
------解决方案--------------------分类相同时按ID倒序
select * from AA order by num desc, id desc
------解决方案--------------------用游标试试:
declare @id int
declare rank cursor for
select [id] from AA order by num desc, id desc
open rank
fetch next from rank into @id
while( @@FETCH_STATUS = 0)
begin
select * from AA where [id]=id
fetch next from rank into @id
end
close rank
deallocate rank