Çë½ÌÒ»¸ösql²éѯµÄÎÊÌâ¡£ - MS-SQL Server / Ó¦ÓÃʵÀý
ÓÐÁ½±í£¨T_CAR£©
{
CAR_ID INT IDENTITY
CUST_ID INT
}
(T_CUSTOMER)
{
CUST_ID INT IDENTITY
CUST_NAME VARCHAR(100)
}
ÏÖÔÚÒª²éѯ±í£¨T_CAR£©ÖÐ×Ö¶ÎCUST_ID²»´æÔÚ±í£¨T_CUSTOMER£©µÄÊý¾Ý
ÒÑÖª²éѯsqlÓÐÁ½¸ö
Ò»£©
SELECT * from T_CAR WHERE CUST_ID NOT IN (SELECT CUST_ID from T_CUSTOMER)
¶þ£©
SELECT * from T_CAR C LEFT JOIN T_CUSTOMER R ON C.CUST_ID=R.CUST_ID WHERE R.CUST_ID IS NULL (ÒÑÖªCUST_IDÔÚ±íT_CARÊÇΨһµÄ¡£)
ÇëÎÊ¡£ÒÔÉÏÁ½ÖÖ²éѯsql£¬ÐÔÄܸüºÃ(ÔÚÈçÏÂÈýÖÖÇé¿öÏ£º1>±íT_CUSTOMERµÄÊý¾ÝÁ¿ºÜ´ó£¬2>±íT_CARµÄÊý¾ÝÁ¿ºÜ´ó£¬ 3>Á½±íµÄÊý¾ÝÁ¿¶¼ºÜ´ó)£¿
ÉÏÃæÁ½¸öÏà±È£¬µÚ¶þ¸ö²éѯЧÂÊ»á¸ß
ѧϰ¡£
select *
from car
left join customer c on car.cust_id=c.cust_id
where c.cust_id is null
Ïà¹ØÎÊ´ð£º
ÎÒÓÐÒ»¸ö±í£¬½á¹¹ÊÇÕâÑù¡£
ת³ö µ¥Î» תÈ뵥λ ±ÊÊý ½ð¶î
date(Ö÷) outid(Ö÷) inid(Ö÷) num amt
2009 1 2 1 500 Ϊ 1 µ¥Î» ÔÚ2009Ä ......
ÏÖÔÚÓÐÁ½ÕÅ±í£ºÎÄÕÂÖ÷±íA(articleId,articleTitle)£¬ÎÄÕÂÆÀÂÛ±íB(commentId,articleId,commentTitle)
ÏÖÔÚÎÒÏëʵÏÖÕâÑùµÄ¹¦ÄÜ£ºÁгöÎÄÕÂÁÐ±í£¬ÆäÖÐÿƪÎÄÕ±êÌâÏÂÃæÁгö´ËÎÄÕµÄÇ°2¸öÎÄÕÂÆÀÂÛ£¬ÇëÎÊsqlÓï¾äÔõôд°¡ ......
ÕâÀïÏëÁ˽âÏ£¬¹ØÓÚSQL ServerÖзÖÒ³ºÍOracleÖзÖÒ³£»
ƽ³£Ð´Ó¦ÓóÌÐòµÄʱºò£¬±ÈÈçÓõÄÓïÑÔÊÇJava£¬ÓиöÁбíÒ³Ã棬ÐèÒª¶ÔÊý¾Ý·ÖÒ³ÏÔʾ£»
ÕâÀïÒª·ÖÒ³ÄѵÀ²»ÐèÒª½èÖúJava£¬¶øÖ±½ÓsqlÄÜÖªµÀ·ÖÒ³Âð£¬ÆðÂëÒ²Òª´«¸öÒ³Âë½ ......
ÏÖÔÚÓÐÒ»¸ö²¿Ãűídept£¨²¿ÃÅÃû³Æ£¬²¿Ãźš£¡££©ÓÐÒ»¸öÈËÔ±±íemp£¨ÐÕÃû£¬ÈËÔ±±àºÅ£¬Ö°Î»£¬Ð½×Ê£¬²¿ÃÅ£©
emp±íÖеÄÄÚÈÝÊÇÕâÑùµÄ£º
a 1 ¹¤³Ìʦ 3000 Èí¼þ²¿
b 2 ÆÕͨԱ¹¤ 2000 Ó²¼þ²¿
c 3 ¹¤³Ìʦ 4000 Ó²¼þ²¿
d ......
ÎÒµÄ×÷ÒµÊÇÿ·ÖÖÓÖ´ÐÐÒ»´Î
ʱ¼ä³¤ÁË»áºÜ´óÂð£¿Ó°ÏìsqlµÄÔËÐÐÂð£¿
ÓÐʲôÓÅ»¯°ì·¨Âð£¿
-- ÄÇÒª¿´ÄãÊÇʲôÑùµÄ×÷ÒµÂÔÚÓÅ»¯µÄͬʱÄÜ·ñÂú×ãÄãµÄ¾ßÌåÐèÇóÂ
-- ¾¡ÎÊһЩ¹ÖÎÊÌ⣬ҲÀµµÃ°ÑÎÊÌâ˵¾ßÌåÒ»µã£¬µ±È˼ ......