SQL语法:
Select * From 表名 Where 条件 Order By Case When 条件 Then 1 Else 0 Desc
SQL实例:
优先显示AllPhoto表中有Price 和caption的图片
Select Top 20 r.* From [AllPhoto] r With (Nolock) Where r.PoiId = 2352
Order By
Case When r.Caption Is Not Null And r.Caption != '' Then 1 Else 0 End Desc,
Case When r.Price Is Not Null And r.Price > 0 Then 1 Else 0 End Desc,
r.SubmitTime Desc,
r.PhotoId Desc