注册 登录
编程论坛 SQL Server论坛

求助:算总学分问题

yunj1105 发布于 2007-03-29 11:24, 1126 次点击
user_ID Course_ID Course_credit
001 011 4
001 012 3
001 013 4
001 014 2
002 011 5
002 012 4
002 013 3
问:怎么统计001和002每个人的总Course_credit,并提取出来?
8 回复
#2
棉花糖ONE2007-03-29 11:51

select sum(Course_credit) from table group by user_ID

#3
yunj11052007-03-29 11:57
是不是算出来的总数就在数据库表中这样啊?
user_ID Course_ID Course_credit
001 011 4
001 012 3
001 013 4
001 014 2
null null 13
002 011 5
002 012 4
002 013 3
null null 12
那算出来之后,怎么把总的提取出来啊?用C#语句
#4
棉花糖ONE2007-03-29 12:34

把你要的结果给出来

#5
初学Delphi2007-03-29 13:16

棉花给你的就是你要的总的
结果是

user_ID 总Course_credit
001 13
002 12

#6
yunj11052007-03-30 09:34
因为要看每个人学分是否修够了,比如规定每人必须修够13个学分,就得从数据库中把每个人的总学分提取出来和总的比较。现在遇到的问题就是:我不知道怎么把算完后总的学分提出来
#7
Kendy1234562007-03-30 09:45
select userid, total_credit = sum(Course_credit) from table group by user_ID
#8
初学Delphi2007-03-30 09:57
select userid, case when sum(Course_credit)>=13 then '已修满' else sum(Course_credit) end from table1 group by user_ID
看看这个是不是能满足你的要求?
#9
yunj11052007-03-30 11:34

恩正好用的上,谢谢两位斑竹

1