zoukankan      html  css  js  c++  java
  • mysql指定某行或者某列的排序

    方法:

    通过desc:

    都无法实现:

    方法一:

    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)

    方法二:

    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:把指定数据行排在前面
    
    如果只是一条数据行,可以这样:
    
    SELECT * FROM user ORDER BY user_id<>7,score DESC;    
    主要是“user_id<>7”,就会把用户id为7的排在前面。
    
    如果是多条数据行:
    SELECT * FROM user ORDER BY user_id NOT IN(7,8,9),score DESC; 
    
    
    
    mysql 某列指定值靠前排序 
    
    单个列靠前排序:
    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代码 会先排列id =263的额数据 然后 根据category_id倒叙
    
    多个列靠前排序:
    
    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 的靠前排
  • 相关阅读:
    Oracle等待事件Enqueue CI:Cross Instance Call Invocation
    Exadata. Are you ready?
    Beyond the Mobile Goldrush
    推荐一款性能诊断工具Membai
    Does LGWR use synchronous IO even AIO enabled?
    Raid Level,该如何为Oracle存储选择才好?
    Oracle备份恢复:Rman Backup缓慢问题一例
    Usage and Configuration of the Oracle shared Server
    UserManaged Backups
    Oracle Recovery Manager Overview and Configuration
  • 原文地址:https://www.cnblogs.com/qmfsun/p/4877331.html
Copyright © 2011-2022 走看看