zoukankan      html  css  js  c++  java
  • mssql sqlserver 指定特定值排在表前面

    转自:http://www.maomao365.com/?p=7141

    摘要:
    下文讲述sql脚本编写中,将 特定值排在最前面的方法分享,
    实验环境:sqlserver 2008 R2



    例:将数据表中指定值为0的行排在最前面呈现给用户

    create table test(keyId int identity,info varchar(10),flag int)
    go
    
    insert into test(info,flag)values ('a',-100),('b',-2),('C',-3)
    ,('d',2),('e',4),('f',8),('g',9),('h',0),('e',1),('f',0)
    go
    
    ---将flag值等于0的放入最前面显示
    select * from test order by 
    case when flag =0 then 0 else 1 end ,
    flag asc 
    go
    
    ---将flag值等于2的放入最前面显示
    select * from test order by 
    case when flag =2 then 0 else 1 end ,
    flag asc 
    go
    
    go
    truncate table test
    drop table test

  • 相关阅读:
    c++笔记3
    c++笔记2
    c++笔记1
    零点追踪(零点及量程补偿)
    优秀软件:
    Hart协议
    RL_RTX函数
    keil-rtx
    电源模块选型
    RTX51 Tiny
  • 原文地址:https://www.cnblogs.com/lairui1232000/p/9755571.html
Copyright © 2011-2022 走看看