有一个表:
ID PWD
odpwe
akdso
smpow
aa bbbbb
mm mksdi
cc dsdsd
要的结果:
ID PWD
aa bbbbb
cc dsdsd
mm mksdi
akdso
smpow
odpwe当ID 不为空时按ID 的升序排,当ID 为空时按PWD 的升序排。
另外。要求只用一个SQL语句。因为我用的是DataSource
这是客户后来的要求。
ID PWD
odpwe
akdso
smpow
aa bbbbb
mm mksdi
cc dsdsd
要的结果:
ID PWD
aa bbbbb
cc dsdsd
mm mksdi
akdso
smpow
odpwe当ID 不为空时按ID 的升序排,当ID 为空时按PWD 的升序排。
另外。要求只用一个SQL语句。因为我用的是DataSource
这是客户后来的要求。
解决方案 »
- 这样写可以吗求解答
- 求一条sql 语句 传入月份 直接输出 这个月的每一天和日期列表
- sql server的,大家补充下
- SQLServer2008Express可以用于商业么
- MYSQL问题怎么这么多
- 以时间为条件的查询
- 怎样找到某条数据的上一条和下一条数据
- 请教这个SQL语句
- 关于SQL Server服务器硬件配置的问题,现在有一个SQL Server用的服务器,并发用户>50(一直维持这么多的并发用户,并发连接大约维持在200
- 一个关于dat文件的问题,很简单!
- 如何在执行存储过程中,不使用dataopensouce方式连接另一台机器,而使用登录映射?
- ORDER BY时候能否讲某一特定记录放到最后
insert into @t select '','odpwe'
union all select '','akdso'
union all select '','smpow'
union all select 'aa','bbbbb'
union all select 'mm','mksdi'
union all select 'cc','dsdsd'select * from @t order by case when ID<>'' then 0 else 1 end,PWD
insert @t select null,'odpwe'
union all select null,'akdso'
union all select null,'smpow'
union all select 'aa','bbbbb'
union all select 'mm','mksdi'
union all select 'cc','dsdsd'
select * from @t
order by case when id is null then 1 else 2 end desc
insert into @t select null,'odpwe'
union all select null,'akdso'
union all select null,'smpow'
union all select 'aa','bbbbb'
union all select 'mm','mksdi'
union all select 'cc','dsdsd'select * from @t order by case when ID is not null then 0 else 1 end,PWD--如果是null值得话
insert into @t select null,'odpwe'
union all select null,'akdso'
union all select null,'smpow'
union all select 'aa','bbbbb'
union all select 'mm','mksdi'
union all select 'cc','dsdsd'select * from @t order by case when ID is not null then 0 else 1 end,PWD
or select * from @t order by case when ID ='' then 0 else 1 end,PWD
最正确的应该是。
declare @t table(ID varchar(10),PWD varchar(10))
insert into @t select null,'odpwe'
union all select null,'akdso'
union all select null,'smpow'
union all select 'zz','bbbbb'
union all select 'mm','mksdi'
union all select 'cc','dsdsd'
select * from @t
select * from @t
order by case when ID is not null then id else (select max(id)+'1' from @t) end,PWD
insert into @t select null,'odpwe'
union all select null,'akdso'
union all select null,'smpow'
union all select 'zz','bbbbb'
union all select 'mm','mksdi'
union all select 'cc','dsdsd'select * from @t order by case when ID is not null then 0 else 1 end,ID,PWD