DROP TABLE IF EXISTS TEST.Sailors ;
DELIMITER //
CREATE TABLE Sailors (
sid int(4) NOT NULL,
sname varchar(20) NOT NULL,
rating int(4) DEFAULT NULL,
age float DEFAULT NULL,
PRIMARY KEY (sid)
) ENGINE=InnoDB DEFAULT CHARSET=euckr COMMENT='2020년 63번'
//
INSERT INTO Sailors (sid,sname,rating,age)
VALUES
(22, 'Dustin', 7, 45.0),
(29, 'Brutus', 1, 33.0),
(31, 'Lubber', 8, 55.5),
(32, 'Andy', 8, 25.5),
(58, 'Rusty', 10, 35.0),
(64, 'Horatio', 7, 35.0),
(71, 'Zorba', 10, 16.0),
(74, 'Horatio', 9, 35.0),
(85, 'Art', 3, 25.5),
(95, 'Bob', 3, 63.5);
① SELECT S.rating, AVG(S.age) AS average
FROM Sailors S
GROUP BY S.rating
HAVING COUNT(*) > 1;
② SELECT S.rating, AVG(S.age) AS average
FROM Sailors S
WHERE S.age >= 18
GROUP BY S.rating
HAVING 1 < (SELECT COUNT(*)
FROM Sailors S2
WHERE S.rating=S2.rating);
③ SELECT S.rating, AVG(S.age) AS average
FROM Sailors S
WHERE S.age >= 18
GROUP BY S.rating
HAVING 1 < (SELECT COUNT(*)
FROM Sailors S2
WHERE S.rating=S2.rating AND
S2.age >= 18);
④ SELECT S.rating, AVG(S.age) AS average
FROM Sailors S
GROUP BY S.rating
HAVING 1 < (SELECT COUNT(*)
FROM Sailors S2
WHERE S.rating=S2.rating);
'정보시스템감리사_데이터베이스' 카테고리의 다른 글
정보시스템 감리사 2022년 57번 문제 (0) | 2023.06.08 |
---|---|
정보시스템 감리사 2023년 65번 문제 (0) | 2023.06.02 |
정보시스템 감리사 2023년 63번 문제 (0) | 2023.06.02 |
정보시스템 감리사 2023년 62번 문제 (0) | 2023.06.02 |
2020년 62번 문제 (0) | 2023.06.02 |