变装俱乐部,隐字联,冰魅文集
摘要:
下文讲述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
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
数据库SQL---数据库、基本表、视图、索引的定义、修改、删除
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (上)
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (下)
网友评论