SQLµÄ×óÁ¬½Ó£¨left join £©
SELECT g.rid, room_no, planed_count,cc from
(SELECT rid,room_no, planed_count from YC_HOTEL_ROOM_T ) r
left join
(SELECT rid,count(*) cc from YC_GUEST_INFO_T group by rid ) g
ON r.rid = g.rid WHERE planed_count<>cc
Ïà¹ØÎĵµ£º
±¾ÎÄ´Ó¶à¸ö½Ç¶È²ûÊöÁËSQL ServerÓë´æ´¢¹ý³ÌµÄ±È½Ï¡£
¢ÙΪʲôҪʹÓô洢¹ý³Ì£¿
ÒòΪËü±ÈSQLÓï¾äÖ´Ðп졣
¢Ú´æ´¢¹ý³ÌÊÇʲô?
°ÑÒ»¶ÑSQLÓï¾äÂÞÔÚÒ»Æð,»¹¿ÉÒÔ¸ù¾ÝÌõ¼þÖ´Ðв»Í¨SQLÓï¾ä¡£
¢ÛÀ´Ò»¸ö×î¼òµ¥µÄ´æ´¢¹ý³Ì£º
CREATE PROCEDURE dbo.testProcedure_AX
AS
select userID from
USERS order by userid ......
Ç°Ò»¶Îʱ¼äÔÚά»¤Ò»¸öÀÏÏîÄ¿µÄʱºò·¢ÏÖ£¬ÔÚÖ´ÐÐÒ»¸ö½Ï´óµÄ´æ´¢¹ý³Ìʱ£¬×ÜÊDZ¨“³£¹æÍøÂç´íÎó£¬Çë¼ì²éÄúµÄÍøÂçÎĵµ”¡£ÔÚºóÐøµÄά»¤¼ì²éÖз¢ÏÖ£¬ÊÇÊÂÎﳬʱµ¼ÖÂÖ´ÐÐÖÐÖ¹µÄ¡£
ÏÂÃæÊǵ÷Õû¹ý³Ì£º
Ò»¡¢°ÑSQL SERVERµÄµÈ´ýÏìӦʱ¼ ......
SQL ServertimestampÊý¾ÝÀàÐÍÓëʱ¼äºÍÈÕÆÚÎ޹ء£SQL ServertimestampÊǶþ½øÖÆÊý×Ö£¬Ëü±íÃ÷Êý¾Ý¿âÖÐÊý¾ÝÐ޸ķ¢ÉúµÄÏà¶Ô˳Ðò¡£ÊµÏÖtimestampÊý¾ÝÀàÐÍ×î³õÊÇΪÁËÖ§³Ö SQL Server »Ö¸´Ëã·¨¡£Ã¿´ÎÐÞ¸Äҳʱ£¬¶¼»áʹÓõ±Ç°µÄ @@DBTS Öµ¶ÔÆä×öÒ»´Î±ê¼Ç£¬È»ºó @@DBTS ¼Ó1¡£ÕâÑù×ö×ãÒÔ°ïÖú»Ö¸´¹ý³ÌÈ·¶¨Ò³Ð޸ĵÄÏà¶Ô´ÎÐò£¬µ«ÊÇtimest ......
Ëø»úÖÆ
NOLOCKºÍREADPASTµÄÇø±ð¡£
1. ¿ªÆôÒ»¸öÊÂÎñÖ´ÐвåÈëÊý¾ÝµÄ²Ù×÷¡£
BEGIN TRAN t
INSERT INTO Customer
SELECT 'a','a'
2. Ö´ÐÐÒ»Ìõ²éѯÓï¾ä¡£
SELECT * from Customer WITH (NOLOCK)
½á¹ûÖÐÏÔʾ"a"ºÍ"a"¡£µ±1ÖÐÊÂÎñ»Ø¹öºó£¬ÄÇôa½«³ÉΪÔàÊý¾Ý¡£(×¢:1ÖеÄÊÂÎñδÌá½») ¡£NOLOCK±íÃ÷ûÓжÔÊý¾Ý±íÌí¼Ó¹²Ï ......