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