if exists(select name from sysobjects where name='tscore')
drop table tscore
go
create table tscore
(
id int identity(1,1) primary key not null,
name varchar(20) not null,
cname varchar(20) not null,
score int not null
)
go
insert into tscore values('关羽','语文',30)
insert into tscore values('关羽','语文',20)
insert into tscore values('关羽','语文',10)insert into tscore values('张飞','数学',50)
insert into tscore values('张飞','数学',40)
insert into tscore values('张飞','数学',30)insert into tscore values('赵云','英语',90)
insert into tscore values('赵云','英语',80)
insert into tscore values('赵云','英语',70)
查询结果:
'关羽','语文',30
'张飞','数学',50
'赵云','英语',90sql聚合
drop table tscore
go
create table tscore
(
id int identity(1,1) primary key not null,
name varchar(20) not null,
cname varchar(20) not null,
score int not null
)
go
insert into tscore values('关羽','语文',30)
insert into tscore values('关羽','语文',20)
insert into tscore values('关羽','语文',10)insert into tscore values('张飞','数学',50)
insert into tscore values('张飞','数学',40)
insert into tscore values('张飞','数学',30)insert into tscore values('赵云','英语',90)
insert into tscore values('赵云','英语',80)
insert into tscore values('赵云','英语',70)
查询结果:
'关羽','语文',30
'张飞','数学',50
'赵云','英语',90sql聚合
解决方案 »
- 取消重复的元组
- 2个表,一个中有“编号”字段,怎么实现在另一个表中接着编号的最后一个往下排序?
- 数据库文件的逻辑文件名有什么用呀?
- SQL递归问题
- 无法启动MSSQLSERVER服务,initerrlog: 无法打开错误日志文件 ''。操作系统错误 = 3(系统找不到指定的路径。)。
- 触发器,插入记录前先检查,如果存在就更新,否则新建,怎么写?
- 查询
- 如何用一句select语句写出交叉表查询(列名不固定)
- 一个SQL语句的挑战,高手请进,送分!
- 能不能把下面的过程简化和性能优化
- SQL语句求解答,急!!
- 我有一些语句,怎么才能做成双击后自动在sql 2000的指定数据库里执行(用户名、密码已知)?
select name,cname,score from tscore a
where score=(select MAX (score) from tscore where a.name=name and a.cname=cname)
order by id
select name,cname,MAX(score) from tscore group by name,cname