-5

JR を除くすべてのレベルについて、レベルとそのレベルの生徒の平均年齢を出力します。

CREATE TABLE STUDENT (
    sid NUMERIC(6) NOT NULL,
    sname VARCHAR(15),
    major VARCHAR(20),
    level VARCHAR(2),
    sage NUMERIC(2) NOT NULL,
    PRIMARY KEY (sid)
);

INSERT INTO STUDENT (sid, sname, major, level, sage) values (1,'JOHN','EE','FR' ,18);
INSERT INTO STUDENT (sid, sname, major, level, sage) values (2,'TIM','EE','FR',19);
INSERT INTO STUDENT (sid, sname, major, level, sage) values (3,'RICHARD','EE','SO',20);
INSERT INTO STUDENT (sid, sname, major, level, sage) values (4,'EDWARD','EE','SO',21);
INSERT INTO STUDENT (sid, sname, major, level, sage) values (5,'ALBER','CS','JR',22);
INSERT INTO STUDENT (sid, sname, major, level, sage) values (6,'MARY','EE','JR',22);
INSERT INTO STUDENT (sid, sname, major, level, sage) values (7,'JACK','EE','SR',23);
INSERT INTO STUDENT (sid, sname, major, level, sage) values (8,'JULIAN','EE','SR',22);
INSERT INTO STUDENT (sid, sname, major, level, sage) values (9,'SAM','EE','SR',24);
INSERT INTO STUDENT (sid, sname, major, level, sage) values (10,'RAM','CS','SR',23);
INSERT INTO STUDENT (sid, sname, major, level, sage) values (11,'RICK','EE','SR',24);
4

2 に答える 2

2
  SELECT level, AVG(sage) AS AvgAge
    FROM STUDENT
   WHERE level != 'JR'
GROUP BY level
于 2012-04-17T18:10:21.740 に答える
0
SELECT level, AVG(sage) 
    FROM STUDENT
    WHERE level <> 'JR' 
    GROUP BY level
于 2012-04-17T18:10:48.253 に答える