您的位置:程序门 -> ms-sql server -> 应用实例



求一条sql语句!特简单


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


求一条sql语句!特简单[已结贴,结贴人:fly0031]
发表于:2007-07-08 10:51:46 楼主
scoid:课目、stid:学号、score:分数
返回以下两门或两门以上课目(scoid)分数(score)低于60分的,学生号(stid)
------
scoid       stid       score
1               1             40
2               1             50
3               1             60
4               2             40
5               2             51
6               2             60
7               3             40
8               3             52
9               3             60
发表于:2007-07-08 10:59:011楼 得分:0
declare   @t   table(scoid   int   identity,stid   int,score   int)
insert   into   @t  
select   1,40   union   all
select   1,50   union   all
select   1,60   union   all
select   2,40   union   all
select   2,51   union   all
select   2,60   union   all
select   3,70   union   all
select   3,52   union   all
select   3,60


select   stid   from   @t   where   score   <   60   group   by   stid
having   count(1)   >   1
发表于:2007-07-08 14:28:192楼 得分:0
这是存储过程吧?我要的是一条sql查询语句
发表于:2007-07-08 14:39:553楼 得分:0
create   table   test(scoid   int,stid   int,score   int)
insert   test   select   1,1,40
union   all   select   2,1,50
union   all   select   3,1,60
union   all   select   4,2,40
union   all   select   5,2,51
union   all   select   6,2,60
union   all   select   7,3,40
union   all   select   8,3,52
union   all   select   9,3,60

go

select   *   from   test   where   score <60

go

drop   table   test

/---------------------结果
1 1 40
2 1 50
4 2 40
5 2 51
7 3 40
8 3 52
发表于:2007-07-08 14:42:094楼 得分:0
select   stid   from   table   where   score   <   60   group   by   stid
having   count(1)   >   1
发表于:2007-07-08 14:44:065楼 得分:0
1楼是1条语句
发表于:2007-07-09 17:51:536楼 得分:10
要求:列出学生成绩两门或者两们以上低于60分的学生号的学生学号及平均成绩。
标准答案如下:
---
select   sc.stid   '学号 ',st.stuname   '姓名 ',avg(sc.score)   '平均分 '
from   score   sc,student   st
where   sc.score> 60   and   sc.stid=st.stid
group   by   sc.stid,st.stuname
having   count(*)> =2



快速检索

最新资讯
热门点击