在SQL中将特定的数据始终排在第一行
将特定的数据始终排在第一行
第一种方式:
select * from ( select Id,1 num from InquiryPurchaseProduct where Id = 50 union select Id,2 num from InquiryPurchaseProduct where Id != 50 ) T order by num asc,Id desc --以升序显示num,并以降序显示Id
执行结果如下图:
第二种方式:
select * from ( select Id,(select max(Id)+1 from InquiryPurchaseProduct) num from InquiryPurchaseProduct where Id = 50 union select Id,Id num from InquiryPurchaseProduct where Id != 50 ) T order by num desc
执行结果如下图: