方法:
通過(guò)desc:
都無(wú)法實(shí)現(xiàn):
方法一:
select sp.productid,sp.productname,ss.sku from sp_product sp inner join sku_skus ss on sp.productid=ss.productid where sp.productname='力士恒久嫩膚嬌膚香皂115g'or sp.productname='佳潔士(Crest) 綠茶薄荷牙膏180克'or sp.productname='心味果園 蘭花豆 190g/袋 1袋 炒貨豆制品休閑零食' order by (case when sp.productid=11042723 then 1 ELSE 2 END)
方法二:
核心sql
select sp.productid,sp.productname,ss.sku from sp_product sp inner join sku_skus ss on sp.productid=ss.productid where sp.productname='力士恒久嫩膚嬌膚香皂115g'or sp.productname='佳潔士(Crest) 綠茶薄荷牙膏180克'or sp.productname='心味果園 蘭花豆 190g/袋 1袋 炒貨豆制品休閑零食' ORDER BY sp.productid not in(11042723)
Mysql:把指定數(shù)據(jù)行排在前面
如果只是一條數(shù)據(jù)行,可以這樣:
SELECT * FROM user ORDER BY user_id<>7,score DESC;
主要是“user_id<>7”,就會(huì)把用戶id為7的排在前面。
如果是多條數(shù)據(jù)行:
SELECT * FROM user ORDER BY user_id NOT IN(7,8,9),score DESC;
mysql 某列指定值靠前排序
單個(gè)列靠前排序:
mysql 某列指定值靠前排序 order by case
SELECT * FROM `jcxsw`.`t_company_product` order by (case when id=263 then 1 ELSE 4 END),category_id desc;
這段sql代碼 會(huì)先排列id =263的額數(shù)據(jù) 然后 根據(jù)category_id倒敘
多個(gè)列靠前排序:
SELECT * FROM `web_membersfastsort_women` m order by m.province<>'10106000' , m.city<>'10106001' ,m.city desc,m.province desc,m.s_cid asc, m.images_ischeck desc,m.pic_num desc limit 2000,30
province =10106000 的 靠前排,在province = 10106000 中 city=10106001 的靠前排
新聞熱點(diǎn)
疑難解答
圖片精選