2つのテーブルの下に参加したい
学生用テーブル:
CREATE TABLE "STUDENT"
( "STUDENT_ID" NUMBER(5,0),
"STUDENT_NAME" VARCHAR2(20),
CONSTRAINT "STUDENT_PK" PRIMARY KEY ("STUDENT_ID") ENABLE
)
/
データ
SID STUDENT_NAME
- 101 Rao
- 102 G.Naidu
- 103 D.Sujith
- 104 V.S.Raja
- 105 R.Johnny
- 106 V.Hemanth
- 107 Ram
- 108 Aditya
- 109 bharat
- 110 Ramesh
出席表:
CREATE TABLE "ATTENDANCE"
( "DAY" DATE,
"SID" NUMBER(5,0),
"PRESENT" NUMBER(5,0),
PRIMARY KEY ("SID", "DAY") ENABLE,
FOREIGN KEY ("SID")
REFERENCES "STUDENT" ("STUDENT_ID") ENABLE
)
/
データ
- ##DAY## ##SID## ##PRESENT##
- 28-MAY-12 101 1
- 28-MAY-12 102 1
- 28-MAY-12 103 0
- 28-MAY-12 104 1
- 28-MAY-12 105 0
- 29-MAY-12 101 0
- 29-MAY-12 102 1
- 29-MAY-12 103 1
- 29-MAY-12 104 1
- 29-MAY-12 105 0
select sid,count(sid) from attendance where present=1 group by sid order by sid;
- SID COUNT(SID)
- 101 2
- 102 2
- 104 2
- 105 1
- 106 1
- 107 2
- 108 2
- 109 2
- 111 2
- 112 1
結果が欲しい...............。
- SID STUDENT_NAME COUNT
- 101 Rao 2
- 102 G.Naidu 1
- 103 D.Sujith 2
- 104 V.S.Raja 1
- 105 R.Johnny 2
- 106 V.Hemanth 1
- 107 Ram 2
- 108 Aditya 2
- 109 bharat 1
- 110 Ramesh 2