表结构学号 分数 科目
1 90 数学
1 91 英语
1 92 语文
1 93 生物
2 90 数学
2 91 英语
2 92 语文
3 91 英语
3 92 语文
3 93 生物求每个学号的总分,最高分,以及最高分对应的科目。怎么写sql,不要用with
1 90 数学
1 91 英语
1 92 语文
1 93 生物
2 90 数学
2 91 英语
2 92 语文
3 91 英语
3 92 语文
3 93 生物求每个学号的总分,最高分,以及最高分对应的科目。怎么写sql,不要用with
解决方案 »
- 如何实现对B机的访问转发为对C机的访问
- 求高人解答。为什么PL/SQL指定了其他表空间,但是还是导入到SYSTEM表空间里面去了?
- 关于oracle索引问题
- 问一下简单的操作,各位大侠务必帮忙哦!!关于oracle帐号问题?
- 急!如何实现将oracle数据库中某张表的数据定时导出到SQL server中去
- 如何远程启动oracle数据库?如果没有操作系统连接权限的话。
- 看看这几道题是不是你想象中那么简单,先做出来先给分
- 一个很奇怪的sql问题!
- 要使用dbms_alert需要在oracle上装什么包?
- BLOB字段的数据如何使用select显示。
- Oracle中多表联合查询。求如何对查询结果去重?
- 急求一个SQL 谢谢!!!!
(select 学号 , sum(分数) "总分" , max(分数) "最高分" from tb group by 学号),
(select t.* from tb t where 分数 = (select max(分数) from tb where 学号 = t.学号)) n
where m.学号 = n.学号
order by m.学号select m.* , n.科目 from
(select 学号 , sum(分数) "总分" , max(分数) "最高分" from tb group by 学号),
(select t.* from tb t where not exists (select 1 from tb where 学号 = t.学号 and 分数 > t.分数)) n
where m.学号 = n.学号
order by m.学号
highest.score as highscore, highest.sub
from
(select sno, sum(score) sumsc from test_yixl group by sno) sumscore,
(select sno, score, sub from (select sno, score, sub, row_number() over (partition by sno order by score desc) cnt
from test_yixl) where cnt = 1) highest
where sumscore.sno = highest.sno;
CREATE TABLE JBGSW.STUDENTSCORE
(
XUEHAO NUMBER,
FENSHU NUMBER,
KEMU VARCHAR2(50 BYTE)
)
--插入测试数据--SQL code
select c.xuehao as 学号,zfenshu as 总分,fenshu as 最高分,kemu as 科目 from(
select xuehao,sum(fenshu) as zfenshu from STUDENTSCORE
group by xuehao
)c,
(
select a.xuehao,kemu,fenshu from STUDENTSCORE a ,(select xuehao,max(fenshu) as gfenshu from STUDENTSCORE group by xuehao)b where a.xuehao=b.xuehao and a.fenshu=b.gfenshu
)d where c.xuehao=d.xuehao
from (select 学号 AS studentNo,MAX(分数) AS 最高分,sum(分数) AS 总分 from 表A
group by studentNo) B,表A
where B.studentNo=A.学号 and A.分数=B.最高分;
(SELECT id,SUM(score) total,MAX(score) mx FROM a GROUP BY ID) b
WHERE a.Id=b.ID AND a.score=b.mx;
---
select 学号,max(分数),max(科目)keep(dense_rank first order by 分数 desc)
from t1
group by 学号;--
select 学号,分数,科目
from (select 学号,分数,科目,case when max(分数)over(partition by 学号)=分数 then 1 else 0 end flag
from t1)
where flag = 1
(
select sno,sum(score) sum_score,max(score) max_score from tbsql group by sno
) a
where T.SNO=a.sno and T.SCORE=a.max_score
测试成功!
(
select m.id sum(m.sore),avg(s.sore) from table m
group by m.id
) on s.id=m.id
create table T005
(
stu_no varchar2(20),
score varchar2(20),
subjects varchar2(20)
);insert into T005 values('1','90','数学');
insert into T005 values('1','91','英语');
insert into T005 values('1','92','语文');
insert into T005 values('1','93','生物');
insert into T005 values('2','90','数学');
insert into T005 values('2','91','英语');
insert into T005 values('2','92','语文');
insert into T005 values('3','91','英语');
insert into T005 values('3','92','语文');
insert into T005 values('3','93','生物');
select t1.stu_no,
t2.sum_score,
t2.top_score,
t1.subjects
from t005 t1,(select stu_no,
sum(score) as sum_score,
max(score) as top_score
from t005
group by stu_no) t2
where t1.stu_no = t2.stu_no
and t1.score = t2.top_score
order by stu_no;STU_NO SUM_SCORE TOP_SCORE SUBJECTS
1 366 93 生物
2 273 92 语文
3 276 93 生物