在一个表中有 ‘名称’,‘编号’,‘id’,其中不同的标号对应不同的名称类型,比如编号=‘A018'表示行政区域名称,有北京上海这些,编号=’A019‘ 表示建设状态,有建设中,完成等状态,现在我想查询 行政区域、建设状态,分两列显示,SQL语句该怎么写啊?
解决方案 »
- sql server 2000 日志满了之后,能设置自动删除吗?
- 有点难的横向显示
- 求一连接ACCESS的SQL语句。。详情请进,在线等待解决。。谢谢:)
- 求一个sql语句!!急急,各位大哥多多帮忙!
- 还是数据更新问题,高手指点
- 求一条简单的统计排序sql
- 请帮看看这段删除表的程序
- 有哪位大哥大姐用过AXIS 2100 网络摄像机,进来帮我看看,谢了
- 关于SQL语句的like
- 这种sq语句怎么写,尝试了一个上午都失败了,特来求助
- sqlserver,以字段中被逗号分隔的字符串分组查询应该怎么做?
- java 连接sqlserver 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused:
try this:select case when 编号='A018' then 名称 end as 行政区域名称,
case when 编号='A019' then 名称 end as 建设状态,
*
from tb
select IIF( 编号='A018' , 名称 ,null) as 行政区域名称,
IIF( 编号='A019' , 名称,NULL) as 建设状态,
from tb
)t
select 'A019',N'建设中',1 union all
select 'A018',N'北京',2 union all
select 'A019',N'完成',3 union all
select 'A018',N'上海',4
)
select * from tb
/*
Code Name no
A019 建设中 1
A018 北京 2
A019 完成 3
A018 上海 4
*/
;with tb(Code,[Name],no) as (
select 'A019',N'建设中',1 union all
select 'A018',N'北京',1 union all
select 'A019',N'完成',2 union all
select 'A018',N'上海',2
)
select no,max(case when code='A018' then [Name] else '' end) as city,max(case when code='A019' then [name] else '' end) as status from tb
group by no
/*no city status
1 北京 建设中
2 上海 完成
*/