简单的sql转置
来源:互联网 发布:c语言 mobi 编辑:程序博客网 时间:2024/06/05 19:47
--创建表
create table score
(
[id] varchar(10),
[name] varchar(10),
score varchar(20),
sc decimal(18,4)
)
go
--修改列属性
alter table score
alter column sc decimal(18,2)
go
--测试数据
insert into score values('01','a','语文',80)
insert into score values('01','a','数学',70)
insert into score values('01','a','英语',90)
insert into score values('02','b','语文',85)
insert into score values('02','b','数学',75)
insert into score values('02','b','英语',95)
go
方法一:
select * from score
select distinct [id],[name],语文=(select sc from score where [id]=s.[id] and score='语文')
,数学=(select sc from score where [id]=s.[id] and score='数学')
,英语=(select sc from score where [id]=s.[id] and score='英语')
from score as s
方法二:
select [id],[name],语文=max(case score
when '语文' then sc
end)
,数学=max(case score
when '数学' then sc
end)
,英语=max(case score
when '英语' then sc
end)
from score
group by [id],[name]
- 简单的sql转置
- SQL的简单查询
- 一个简单的sql
- 简单的SQL命令
- 简单的SQL语句
- 简单的SQL语句
- 纵表转横表简单的sql
- 简单的SQL语句
- sql 简单的错误
- 简单的sql语句。
- sql简单的语句
- 简单的sql语句
- 简单的多表联查sql
- 简单的sql操作
- SQL的简单应用
- 简单的SQL语句
- 简单的sql题
- SQL简单的分页
- 有效的测试设计
- HTTP 1.1 协议部分解释
- Linux C notes (BOOK UNIX)
- 提高数据库SQL语句查询速度的几个方法(转)
- 开通博客了!
- 简单的sql转置
- 文章推荐规则说明
- db2插入 timestamp 类型字段 的sql
- oracle取字符串长度的函数length()和hengthb()
- Linux 2.6内核的新锁机制-RCU
- 程序员需知的五种静态代码审查
- ORA-39001 ORA-01775: looping chain of synonyms解决方法
- 选择框架时需要注意的问题
- Latex中使用dvipdfm转换方式hyperref包生成PDF中文书签乱码的解决方案