如何消除sql中的重复?

时间:2013-10-04 22:00:17

标签: sql

有人能指出我正确的方向来消除学生ID字段中的重复吗?

SQL> select DISTINCT(student_class.student_id) as student_Num,student_class.class_id,
  2  event.event_id, event.event_name
  3  from student_class, event
  4  where student_class.class_id = '10'
  5  and event.class_id = '10';

STUDENT_NUM   CLASS_ID   EVENT_ID EVENT_NAME
----------- ---------- ---------- --------------------------------------------------
         12         10          2 Flag FOOtball Game
         12         10          5 PICKUP SOCCER GAME
          9         10          5 PICKUP SOCCER GAME
         16         10          5 PICKUP SOCCER GAME
          6         10          2 Flag FOOtball Game
         18         10          5 PICKUP SOCCER GAME
          4         10          5 PICKUP SOCCER GAME
          4         10          2 Flag FOOtball Game
         16         10          2 Flag FOOtball Game
         20         10          2 Flag FOOtball Game
          3         10          5 PICKUP SOCCER GAME
          2         10          5 PICKUP SOCCER GAME
          3         10          2 Flag FOOtball Game
          8         10          2 Flag FOOtball Game
          9         10          2 Flag FOOtball Game
          2         10          2 Flag FOOtball Game
          6         10          5 PICKUP SOCCER GAME
         20         10          5 PICKUP SOCCER GAME
         18         10          2 Flag FOOtball Game
          8         10          5 PICKUP SOCCER GAME

1 个答案:

答案 0 :(得分:0)

尝试 SQL>

  SELECT DISTINCT event.event_id,event.event_name,COUNT(student_class.student_id) AS 'Total Students'
   FROM student_class, event
   WHERE student_class.class_id = '10'
   AND event.class_id = '10' 
     GROUP BY event.event_id,event.event_name,student_class.student_id

这应该为您提供活动ID和姓名,其中包含数字的学生。