刚入门,关于选课系统的几个问题:(多谢大家!)
1.选修学生最多的课程
2.没有人选的课程列表
3.求....的列表问题是不是最后都需要加Group By?
4.Select Distinct T_stud.studName中为了消除重复
  Distinct这样用对么?
四个表如下:
T_stud(学生)
studNo 学号
studName 姓名
studSex 性别
studAge 年龄
T_Sub (课程)
subNo 课程编号
subName 课程名称
teacherNo 教师编号
T_teacher(教师)
teacherNo 教师编号
teacherName 姓名
teacherAge 年龄
T_select(选课)
studNo 学生学号
subNo 课程编号
score 分数

解决方案 »

  1.   

    1:select top 1 subNO,count(1) as '人数' from T_select group by subNO order by count(1) desc 
      

  2.   


    select count(课程编号)
    from 选课
    group by 课程编号
      

  3.   

    2.select subNO from T_sub where not exists(select distinct subNO from T_select)
      

  4.   


    2.
    select 课程编号
    from 课程 a
    where not exists(
    select 1
    from 选课 b
    where a.课程编号=b.课程编号)
      

  5.   

    3.不一定的,group是把一样的分为一组,并统计的
    4.是这样用的
      

  6.   

    1错了,应该
    select count(课程编号)
    from 选课
    group by 课程编号