SQL > SQL????? > Subquery

??? ??? SQL??? ?? SQL??? ??? ????. ??? WHERE ?,? HAVING ?? ??SQL ??? ??? ??, ??? ??? subquery ??? ?? ???. Subquery? ??? ?????? ?? ??? ???? ??. ??? ???? subquery? ??? ??? ???? ??? ????? ???.

Subquery ? ??? ??? ????:

SELECT "??1"
FROM "??1"
WHERE "??2" [?????]
(SELECT "??1"
FROM "??2"
WHERE "??");

[?????] ?? ?????? ????.? =, >, <, >=, <=. ??? ??? ?? ?????? ????. ?? ?? "LIKE."

??? ?? SQL??? ???? ????? ?? ???:

Store_Information ??
Store_NameSalesTxn_Date
Los Angeles150005-Jan-1999
San Diego25007-Jan-1999
Los Angeles30008-Jan-1999
Boston70008-Jan-1999

Geography ??
Region_NameStore_Name
EastBoston
EastNew York
WestLos Angeles
WestSan Diego

??? subquery ? ???? ?? ??? ?? ???? ?????. ??? ?? SQL? ? ??? ???? ????.

SELECT SUM(Sales) FROM Store_Information
WHERE Store_Name IN
(SELECT Store_Name FROM Geography
WHERE Region_Name = 'West');

??:

SUM(Sales)
2050

? ??? ??? ??? ??? ?? ???? ?? ?? ??? ???? ?? ????? ??? ?? ??? ?? ??? ??? ? ???? ? ???? ????? ???????.

SQL UNION >>
?


Copyright © 2021   1keydata.com   All Rights Reserved