select 学号,姓名, 课程,成绩 from 表 group by 学号,姓名 order by 学号,姓名
楼上那位好像错了,有点想当然的感觉吗。 如果后台是SQL 或者是SYBASE的话比较好写,ORACLE没写过 为了避免中文字断假设Table结构为create table a(xh int,xm char(8), kc char(20),cj numeric(5,1))要实现效果语句为select xh, xm, sum(case kc when '网络' then cj else 0 end) as '网络', sum(case kc when '英语' then cj else 0 end )as '英语', sum(case kc when '高数' then cj else 0 end )as '高数', sum(cj) as '总分' from a group by xh,xm order by xh
好像有点复杂。不会那么简单吧。 笨办法: select bb from tablename distinct得到课程序列 select * from tablename order by aa,bb 之后在课程序列中比较。不过这样的确很笨。呵呵。
这是sql语句的问题,不是编程的问题,你可以通过sql语句进行count and union就可以了,至于显示的方法直接重结果机中毒出来就行了
swain(球球) : 该类问题,单纯用SQL解决不了!
楼上那位好像错了,有点想当然的感觉吗。 如果后台是SQL 或者是SYBASE的话比较好写,ORACLE没写过 为了避免中文字断假设Table结构为create table a(xh int,xm char(8), kc char(20),cj numeric(5,1))要实现效果语句为select xh, xm, sum(case kc when '网络' then cj else 0 end) as '网络', sum(case kc when '英语' then cj else 0 end )as '英语', sum(case kc when '高数' then cj else 0 end )as '高数', sum(cj) as '总分' from a group by xh,xm order by xh ALLTEC 同学: 那别人的这个解答你觉得不可以解决吗? 你第二次的表和第一次的表有什么对应嘛! (莫非一个学好可以供两个人使用?如果在第二个表里面省略了学号或姓名字段之一,那我认为你的问题也是可以用它解决的。)
group by 学号,姓名
order by 学号,姓名
如果后台是SQL 或者是SYBASE的话比较好写,ORACLE没写过
为了避免中文字断假设Table结构为create table a(xh int,xm char(8), kc char(20),cj numeric(5,1))要实现效果语句为select xh, xm, sum(case kc when '网络' then cj else 0 end) as '网络',
sum(case kc when '英语' then cj else 0 end )as '英语',
sum(case kc when '高数' then cj else 0 end )as '高数',
sum(cj) as '总分'
from a
group by xh,xm
order by xh
AA BB CC
0001 A200001 20
0001 A200002 40
0002 A200001 1
0002 A200002 29
0003 A200001 40
0003 A200003 50
结果示意
A200001 A200002 A200003 ...
0001 20 40 0
0002 1 29 0
0003 40 0 5
有劳各位 多谢
笨办法:
select bb from tablename distinct得到课程序列
select * from tablename order by aa,bb
之后在课程序列中比较。不过这样的确很笨。呵呵。
如果后台是SQL 或者是SYBASE的话比较好写,ORACLE没写过
为了避免中文字断假设Table结构为create table a(xh int,xm char(8), kc char(20),cj numeric(5,1))要实现效果语句为select xh, xm, sum(case kc when '网络' then cj else 0 end) as '网络',
sum(case kc when '英语' then cj else 0 end )as '英语',
sum(case kc when '高数' then cj else 0 end )as '高数',
sum(cj) as '总分'
from a
group by xh,xm
order by xh
ALLTEC 同学:
那别人的这个解答你觉得不可以解决吗?
你第二次的表和第一次的表有什么对应嘛!
(莫非一个学好可以供两个人使用?如果在第二个表里面省略了学号或姓名字段之一,那我认为你的问题也是可以用它解决的。)