SQL语句的一个例子
admin 发布于:2010-04-14 16:14:00
阅读:loading
题目是这样的,现在这里贴出来创建表的SQL语句,有兴趣的朋友可以试试身手。呵呵
MsSql语法:
建表语句:
--drop table cj
create table CJ(
name varchar(20) ,
subject varchar(10),
result int
)
insert into cj values('张三','英语',80);
insert into cj values('张三','数学',90);
insert into cj values('张三','物理',85);
insert into cj values('李四','语文',85);
insert into cj values('李四','数学',92);
insert into cj values('李四','物理',82);
我用的一个写法应该说不是很好吧,如下:
select distinct name ,(select result from cj where subject = '语文' and name = cc.name) as '语文'
,(select result from cj where subject = '数学' and name = cc.name) as '数学'
,(select result from cj where subject = '物理' and name = cc.name) as '物理'
from cj as cc
原表截图为:
我的SQL语句查询出来的结果截图为:
点赞