SQLÓïÑÔ»ù´¡£¨1£©
¶ÔÏóÃüÃûµÄÔ¼¶¨£ºÊý¾Ý¿âÃû.ËùÓÐÕßÃû.¶ÔÏóÃû
Ç°Á½Õß¿ÉÊ¡ÂÔ£¬Ä¬ÈÏÖµÊý¾Ý¿âÊǵ±Ç°Êý¾Ý¿â£¬ËùÓÐÕßÊÇdbo
±ðÃû£ºÊý¾Ý¿âÃû³Æ as Êý¾Ý¿â±íÃû Ö÷ÒªÊÇÔö¼ÓselectÓï¾äµÄ¿É¶ÁÐÔ£¬Èç¹ûÒѾΪÊý¾Ý±íÖƶ¨Á˱ðÃû£¬Ôò
ÔÚÏàÓ¦µÄSQLÓï¾äÖУ¬¶Ô¸ÃÊý¾Ý±íµÄËùÓÐÏÔʾÒýÓö¼ÒªÊ¹ÓñðÃû£¬¶ø²»ÄÜʹÓÃÊý¾Ý±íÃû¡£
selectÓï¾äÊÇÊý¾Ý¼ìË÷ÖÐ×îƵ·±µÄ»î¶¯£¬ÔÙ¼ìË÷Ç°ÒªÏÈÖªµÀ´æ´¢ÔÚÄÄÀselectÓï¾ä¿ÉÒÔÓɶà¸ö
²éѯ×ÓÓï¾ä×é³É£¬¶øÇÒ¿ÉÒÔǶÌס£
selectÓï¾ä¿ÉÒÔ¼ìË÷£ºÈ«²¿ÐÐÁУ¬È«²¿ÐкÍÌض¨ÁУ¬ÏÞ¶¨·¶Î§µÄÐУ¬ÓëÒ»×éֵƥÅäµÄÐУ¬¸ù¾Ýδֵ֪¼ìË÷
µÄÐУ¬Òþ²ØÓÐÖظ´ÖµµÄÐУ¬¸ù¾ÝËù¸öËÑË÷Ìõ¼þ¼ìË÷µÄÐС£
»ù±¾½á¹¹£ºSELECT [ALL|DISTINCT]select_list
[INTO [new_table_name]]
from{table_name|view_name,...}
[WHERE search_conditons]
[GROUP BY group_by_list]
[HAVING search_conditions]
[ORDER BY order_list [asc|desc]]
WHEREºÍHAVINGµÄÇø±ðÊÇWHEREÊǶÔÕû¸ö±í½øÐÐÑ¡Ôñ£¬¶øHAVINGÔòÊǶԷÖ×éµ±ÖеÄÔªËؽøÐÐÑ¡Ôñ¡£
select×Ó¾ä
SELECT [ALL|DISTINCT] [TOP N] select_list
select_list¼È¿É±íʾ×Ö¶ÎÃû³Æ£¬Ò²¿ÉÒÔÊÇÆäËû±í´ïʽ¡£
allÖ¸¶¨ÔÚ½á¹û¼¯ÖпÉÒÔÏÔʾÖظ´ÐУ¬distinct²»ÏÔʾÏàͬÐУ¬TOP n [PERCENT]Ö¸¶¨Ö»´Ó²éѯ½á¹û¼¯ÖÐÊä³öÇ° n ÐС£n ÊǽéÓÚ 0 ºÍ 4294967295 Ö®¼äµÄÕûÊý¡£Èç¹û»¹Ö¸¶¨ÁË PERCENT£¬ÔòÖ»´Ó½á¹û¼¯ÖÐÊä³öÇ°°Ù·ÖÖ® n ÐС£µ±Ö¸¶¨Ê±´ø PERCENT ʱ£¬n ±ØÐëÊǽéÓÚ 0 ºÍ 100 Ö®¼äµÄÕûÊý¡£
Àý×Ó£º
USE NORTHWIND
SELECT PRODUCTID,ORDERID,UnitPrice*Quantity AS SUM
INTO KKKKKK
from [Order Details]
WHERE UnitPrice*Quantity>10000;
AS ×Ó¾ä¿ÉÓÃÀ´¸ü¸Ä½á¹û¼¯ÁÐÃû»òΪµ¼³öÁÐÖ¸¶¨Ãû³Æ¡£Èç´ËÀý£¬sum¸üÇå³þËù±íʾµÄÄÚÈÝ£¬·ñÔò£¬Õâ¸öËãÊõ
ʽ»áÓÉϵͳָ¶¨Ãû³Æ¡£ËùÒÔÔÚ¸ÃÓï¾äµ±ÖÐwhereºóÃæµÄUnitPrice*Quantity²»ÄÜд³Ésum£¬ÒòΪsumÊǽá¹û
¼¯µ±ÖÐʹÓõÄÃû³Æ£¬ÔÚËÑË÷Ìõ¼þÖл¹Ã»Óб»Ö¸¶¨¡£
¶øÇÒÕâ¸öÀý×ÓÖеıí order detailsÖаüº¬¹Ø¼ü×Öorder£¬ËùÒÔ²»ÄÜÖ±½ÓÓã¬Òª¼Ó[]¡£
Ïà¹ØÎĵµ£º
Ê×ÏÈ£º·ÖÀëÊý¾Ý¿â
ÆóÒµ¹ÜÀíÆ÷--ÓÒ¼üsuspectµÄÊý¾Ý¿â--ËùÓÐÈÎÎñ--·ÖÀëÊý¾Ý¿âÈ»ºó±¸·ÝÄãµÄsuspectÊý¾Ý¿âµÄÎļþ,ÔÙ°´ÏÂÃæµÄ²½Öè´¦Àí:
1.н¨Ò»¸öͬÃûµÄÊý¾Ý¿â
2.ÔÙÍ£µôsql server
3.ÓÃsuspectÊý¾Ý¿âµÄÎļþ¸²¸ÇµôÕâ¸öн¨µÄͬÃûÊý¾Ý¿â
4.ÔÙÖØÆôsql server
5.´Ëʱ´ò¿ªÆóÒµ¹ÜÀíÆ÷ʱн¨µÄͬÃûÊý¾Ý¿â»á³öÏÖÖÃÒÉ£¬ÏȲ» ......
50¸öSqlÓï¾ä£¬½ö¹©Ñ§Ï°£¡
Student(S#,Sname,Sage,S***) ѧÉú±í
Course(C#,Cname,T#) ¿Î³Ì±í
SC(S#,C#,score) ³É¼¨±í
Teacher(T#,Tname) ½Ìʦ±í
ÎÊÌ⣺
1¡¢²éѯ“001”¿Î³Ì±È“002”¿Î³Ì³É¼¨¸ßµÄËùÓÐѧÉúµÄѧºÅ£»
select a.S# from (select s#,score from SC ......
ÎÒÃÇÒª×öµ½²»µ«»áдSQL,»¹Òª×öµ½Ð´³öÐÔÄÜÓÅÁ¼µÄSQL,ÒÔÏÂΪ±ÊÕßѧϰ¡¢ÕªÂ¼¡¢²¢»ã×ܲ¿·Ö×ÊÁÏÓë´ó¼Ò·ÖÏí£¡
£¨1£© Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
ORACLE µÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom× ......
SQL ServerÔÚ°²×°µ½·þÎñÆ÷ÉϺó£¬ÓÉÓÚ³öÓÚ·þÎñÆ÷°²È«µÄÐèÒª£¬ËùÒÔÐèÒªÆÁ±ÎµôËùÓв»Ê¹ÓõĶ˿ڣ¬Ö»¿ª·Å±ØÐëʹÓõĶ˿ڡ£ÏÂÃæ¾ÍÀ´½éÉÜÏÂSQL Server 2008ÖÐʹÓõĶ˿ÚÓÐÄÄЩ£º
Ê×ÏÈ£¬×î³£ÓÃ×î³£¼ûµÄ¾ÍÊÇ1433¶Ë¿Ú¡£Õâ¸öÊÇÊý¾Ý¿âÒýÇæµÄ¶Ë¿Ú£¬Èç¹ûÎÒÃÇÒªÔ¶³ÌÁ¬½ÓÊý¾Ý¿âÒýÇ棬ÄÇô¾ÍÐèÒª´ò¿ª¸Ã¶Ë¿Ú¡£Õâ¸ö¶Ë¿ÚÊÇ¿ÉÒÔÐ޸ĵģ¬ÔÚ&ldqu ......
²éѯÓï¾ä
Óï·¨¸ñʽ£º
SELECT
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_
[SQL_CACHE | SQL_ ......