SELECT top 36 id,roomName,bgImg,qqImg,listCount FROM room where [status]=2 ORDER BY listCount DESC,id asc
我想让这个结果里一定要包含id=1的那一行,如果有就按默认listCount asc排列,没有就加到最后一行,但一定要有,因为listCount 是会变化的.没有的话加上了变成37行了也没关系
------解决方案--------------------
SELECT DISTINCT TOP 36
id ,
roomName ,
bgImg ,
qqImg ,
listCount
FROM ( SELECT id ,
roomName ,
bgImg ,
qqImg ,
listCount
FROM room
WHERE id = 1
UNION ALL
SELECT TOP 37
id ,
roomName ,
bgImg ,
qqImg ,
listCount
FROM room
WHERE [status] = 2
ORDER BY listCount DESC ,
id ASC
) T
ORDER BY listcount ASC
------解决方案--------------------