我已經提供了以下關係模式 -在這種情況下如何做多個選擇操作?
country (countrycode,name,capital) &
population (populationcode,population,countrycode)
哪裏COUNTRYCODE是外鍵w.r.t.關係國家。我必須用最大的人口來投射這個國家,但是聚合操作MAX(population)
對於給定的命令並不直接工作 - 。
SELECT pcode, ccode, name, capital
FROM population NATURAL JOIN country
WHERE ((SELECT MAX(population) as maxpopulation FROM population NATURAL JOIN country))
對於給定的一組數據 -
INSERT INTO country VALUES(1,'INDIA','NEW DELHI');
INSERT INTO country VALUES(2,'U.S.A.','WASHINGTON DC');
INSERT INTO country VALUES(3,'U.K.','LONDON');
INSERT INTO country VALUES(4,'CHINA','BEIJING');
INSERT INTO country VALUES(5,'JAPAN','TOKYO');
INSERT INTO population VALUES(1,1200000000,1);
INSERT INTO population VALUES(2,350000000,2);
INSERT INTO population VALUES(3,65640000,3);
INSERT INTO population VALUES(4,1300000000,4);
INSERT INTO population VALUES(5,127000000,5);
由於它是製造在終端下面的輸出 -
+-------+-------+--------+---------------+
| pcode | ccode | name | capital |
+-------+-------+--------+---------------+
| 1 | 1 | INDIA | NEW DELHI |
| 2 | 2 | U.S.A. | WASHINGTON DC |
| 3 | 3 | U.K. | LONDON |
| 4 | 4 | CHINA | BEIJING |
| 5 | 5 | JAPAN | TOKYO |
+-------+-------+--------+---------------+
5 rows in set (0.00 sec)
和期望輸出是 -
+-------+-------+--------+---------------+
| pcode | ccode | name | capital |
+-------+-------+--------+---------------+
| 4 | 4 | CHINA | BEIJING |
+-------+-------+--------+---------------+
1 rows in set (0.00 sec)
但它應該onl y告訴中國人口最多的國家屬性。
那麼可以進行哪種操作?
忘記NATURAL JOIN構造,指定連接條件! – jarlh
指定預期的結果! (順便說一句,你需要一個相關的子查詢。) – jarlh
@jarlh我添加了預期的結果。 –