a. , s. พวกนี้เนี่ยแทนค่าจากตารางมาเป็นตัวย่อน่ะครับ จะได้อ้างถึงง่ายๆ
ย่อโดยเอาชื่อตารางแล้ววรรค1ทีตามด้วยชื่อที่อยากให้เป็น
select sum(a.area_male_population) + sum(a.area_female_population) เลือกค่าซัมมา+กัน
from
tbl_country c,
tbl_state s,
tbl_area a จากตาราง
tbl_country ย่อให้เป็น c
tbl_state ย่อให้เป็น s
tbl_area ย่อให้เป้น a
where a.state_id = s.state_id
and s.country_id = c.country_id
and c.country_id = xxx
แวร์ที่ state_id ของตาราง tbl_area ที่เท่ากันกับ state_id ของตาราง tbl_state
และ country_id ของตาราง tbl_state ที่เท่ากันกับcountry_id ของตาราง tbl_country
และ country_id ของตาราง tbl_country มีค่าเท่ากับ ประเทศที่มี country_id นั้น
SELECT SUM(area_male_population) + SUM(area_female_population) AS population
FROM tbl_area WHERE state_id IN (
SELECT state_id FROM tbl_state WHERE country_id IN (
SELECT country_id FROM tbl_coutry WHERE country_id = xxx
));
ประมาณนี้ครับ
ของไอซ์จะ ซีเลคหลายรอบหน่อย เป็นลำดับๆไปน่ะ
FROM tbl_area WHERE
state_id IN
(
SELECT state_id FROM tbl_state WHERE country_id IN
(
SELECT country_id FROM tbl_coutry WHERE country_id =
xxx )
);
เอา state_id ใน ตาราง tbl_state ที่มีค่า country_id เท่ากับกับ country_id ใน tbl_coutry ซึ่ง country_id =
xxxเข้าใจแต่อธิบายไม่ถูก
