Ìá¸ßSQLÖ´ÐÐЧÂʵļ¸µã½¨Òé
from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í£¬driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏ£¬Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡£
¡¡¡¡Ìá¸ßSQLÖ´ÐÐЧÂʵļ¸µã½¨Òé:
¡¡¡¡¡ô¾¡Á¿²»ÒªÔÚwhereÖаüº¬×Ó²éѯ;
¡¡¡¡¹ØÓÚʱ¼äµÄ²éѯ£¬¾¡Á¿²»ÒªÐ´³É£ºwhere to_char(dif_date,'yyyy-mm-dd')=to_char('2007-07-01','yyyy-mm-dd');
¡¡¡¡¡ôÔÚ¹ýÂËÌõ¼þÖУ¬¿ÉÒÔ¹ýÂ˵ô×î´óÊýÁ¿¼Ç¼µÄÌõ¼þ±ØÐë·ÅÔÚwhere×Ó¾äµÄĩβ;
¡¡¡¡from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í£¬driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏ£¬Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡£Èç¹ûÓÐÈý¸öÒÔÉϵÄÁ¬½Ó²éѯ£¬ÄǾÍÐèҪѡÔñ½»²æ±í(intersection table)×÷Ϊ»ù´¡±í£¬½»²æ±íÊÇÖ¸ÄǸö±»ÆäËû±íËùÒýÓõıí;
¡¡¡¡¡ô²ÉÓð󶨱äÁ¿
¡¡¡¡¡ôÔÚWHEREÖо¡Á¿²»ÒªÊ¹ÓÃOR
¡¡¡¡¡ôÓÃEXISTSÌæ´úIN¡¢ÓÃNOT EXISTSÌæ´úNOT IN;
¡¡¡¡¡ô±ÜÃâÔÚË÷ÒýÁÐÉÏʹÓüÆË㣺WHERE SAL*12>25000;
¡¡¡¡¡ôÓÃINÀ´Ìæ´úOR£º WHERE LOC_ID=10 OR LOC_ID=15 OR LOC_ID=20
¡¡¡¡¡ô±ÜÃâÔÚË÷ÒýÁÐÉÏʹÓÃIS NULLºÍIS NOT NULL;
¡¡¡¡¡ô×ÜÊÇʹÓÃË÷ÒýµÄµÚÒ»¸öÁÐ;
¡¡¡¡¡ôÓÃUNION-ALLÌæ´úUNION;
¡¡¡¡¡ô±ÜÃâ¸Ä±äË÷ÒýÁеÄÀàÐÍ£ºSELECT...from EMP WHERE EMPNO='123'£¬ÓÉÓÚÒþʽÊý¾ÝÀàÐÍת»»£¬to_char(EMPNO)='123'£¬Òò´Ë£¬½«²»²ÉÓÃË÷Òý£¬Ò»°ãÔÚ²ÉÓÃ×Ö·û´®Æ´´Õ¶¯Ì¬SQLÓï¾ä³öÏÖ;
¡¡¡¡¡ô'!=' ½«²»Ê¹ÓÃË÷Òý;
¡¡¡¡¡ôÓÅ»¯GROUP BY;
¡¡¡¡¡ô±ÜÃâ´øÓÐLIKE²ÎÊýµÄͨÅä·û£¬LIKE '4YE%'ʹÓÃË÷Òý£¬µ«LIKE '%YE'²»Ê¹ÓÃË÷Òý
¡¡¡¡¡ô±ÜÃâʹÓÃÀ§ÄѵÄÕý¹æ±í´ïʽ£¬ÀýÈçselect * from customer where zipcode like "98___"£¬¼´±ãÔÚzipcodeÉϽ¨Á¢ÁËË÷Òý£¬ÔÚÕâÖÖÇé¿öÏÂÒ²»¹ÊDzÉÓÃ˳ÐòɨÃèµÄ·½Ê½¡£Èç¹û°ÑÓï¾ä¸Ä³Éselect * from customer where zipcode>"98000"£¬ÔÚÖ´Ðвéѯʱ¾Í»áÀûÓÃË÷ÒýÀ´²éѯ£¬ÏÔÈ»»á´ó´óÌá¸ßËÙ¶È;
¡¡¡¡¡ô¾¡Á¿Ã÷È·µÄÍê³ÉSQLÓï¾ä£¬¾¡Á¿ÉÙÈÃÊý¾Ý¿â¹¤×÷¡£±ÈÈçдSELECTÓï¾äʱ£¬ÐèÒª°Ñ²éѯµÄ×Ö¶ÎÃ÷È·Ö¸³ö±íÃû¡£¾¡Á¿²»ÒªÊ¹ÓÃSELECT *Óï¾ä¡£×éÖ¯SQLÓï¾äµÄʱºò£¬¾¡Á¿°´ÕÕÊý¾Ý¿âµÄÏ°¹ß½øÐÐ×éÖ¯
ÎÄÕ³ö´¦£ºhttp://database.ctocio.com.cn/160/9182660.shtml
Ïà¹ØÎĵµ£º
----start
·²ÊÇÖªµÀÊý¾Ý¿âµÄÈ˶¼ÖªµÀSQL£¬·²ÊǶÔSQLÓÐÒ»µãÁ˽âµÄÈ˶¼¾õµÃSQLºÜ¼òµ¥£¬·²ÊÇÓÐÕâÖָоõµÄÈ˶¼ÊÇSQLµÃ³õ¼¶Óû§£¬ÒòΪËûѧ»áÁËÔö²éɾ¸Ä¾ÍÒÔΪÕâ¾ÍÊÇSQLµÄÈ«²¿¡£Ä¿Ç°µÄ´ó²¿·ÖÓ¦ÓÃÈí¼þ¶¼ÊÇÒÔÊý¾Ý¿âΪÖÐÐÄ£¬Ëæ×ÅÈí¼þµÄÔËÐУ¬Êý¾ÝÁ¿»áÔ½À´Ô½´ó¡£ÈçºÎÓüò½à¡¢¸ßЧµÄSQLÓï¾ä²Ù×÷Êý¾ÝÏÔµÃÔ½À ......
ʹÓþۼ¯Ë÷ÒýÓÅ»¯SQL²éѯ
Ê×ÏÈÈÃÎÒÃÇ×öÒ»¸ö²âÊÔ£¬ÏÖ´´½¨Ò»¸ö±í Ïò±íÖвåÈë²»µÈÊý¾Ý
--DROP TABLE T_UserInfo--------------------------------------
CREATE
TABLE
T_UserInfo
(
Userid
varchar(20),
UserName varchar(20)
)
--
DECLARE
@I INT
DECLARE
@ENDID INT
SELECT
@I =
1
SELECT
@ ......
ÔÚÑ°ÕÒPowerDesignerÏà¹ØÐÅÏ¢µÄʱºòżȻ·¢ÏÖµÄ.ʹÓÃtimestamp
΢ÈíMSDNÄÚÈÝ:
timestamp (Transact-SQL)
¹«¿ªÊý¾Ý¿âÖÐ×Ô¶¯Éú³ÉµÄΨһ¶þ½øÖÆÊý×ÖµÄÊý¾ÝÀàÐÍ¡£timestamp ͨ³£ÓÃ×÷¸ø±íÐмӰ汾´ÁµÄ»úÖÆ¡£ ´æ´¢´óСΪ 8 ¸ö×Ö½Ú¡£ timestamp Êý¾ÝÀàÐÍÖ»ÊǵÝÔöµÄÊý×Ö£¬²»±£ÁôÈÕÆÚ»òʱ¼ä¡£ ÈôÒª¼Ç¼ÈÕÆÚ»òʱ¼ä£¬ÇëʹÓà datetime ......
¡¡¡¡
¡¡¡¡¡ô¾¡Á¿²»ÒªÔÚwhereÖаüº¬×Ó²éѯ;
¡¡¡¡¹ØÓÚʱ¼äµÄ²éѯ£¬¾¡Á¿²»ÒªÐ´³É£ºwhere to_char(dif_date,'yyyy-mm-dd')=to_char('2007-07-01','yyyy-mm-dd');
¡¡¡¡¡ôÔÚ¹ýÂËÌõ¼þÖУ¬¿ÉÒÔ¹ýÂ˵ô×î´óÊýÁ¿¼Ç¼µÄÌõ¼þ±ØÐë·ÅÔÚwhere×Ó¾äµÄĩβ;
¡¡¡¡from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í£¬driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖа ......