sqlÓÅ»¯2
ÉÏÃæÎÒÃÇÌáµ½µÄÊÇһЩ»ù±¾µÄÌá¸ß²éѯËٶȵÄ×¢ÒâÊÂÏî,µ«ÊÇÔÚ¸ü¶àµÄÇé¿öÏÂ,ÍùÍùÐèÒª·´¸´ÊÔÑé±È½Ï²»Í¬µÄÓï¾äÒԵõ½×î¼Ñ·½°¸¡£×îºÃµÄ·½·¨µ±È»ÊDzâÊÔ£¬¿´ÊµÏÖÏàͬ¹¦ÄܵÄSQLÓï¾äÄĸöÖ´ÐÐʱ¼ä×îÉÙ£¬µ«ÊÇÊý¾Ý¿âÖÐÈç¹ûÊý¾ÝÁ¿ºÜÉÙ£¬ÊDZȽϲ»³öÀ´µÄ£¬Õâʱ¿ÉÒÔÓò鿴ִÐмƻ®£¬¼´£º°ÑʵÏÖÏàͬ¹¦ÄܵĶàÌõSQLÓï¾ä¿¼µ½²éѯ·ÖÎöÆ÷£¬°´CTRL+L¿´²éËùÀûÓõÄË÷Òý£¬±íɨÃè´ÎÊý£¨ÕâÁ½¸ö¶ÔÐÔÄÜÓ°Ïì×î´ó£©£¬×ÜÌåÉÏ¿´Ñ¯³É±¾°Ù·Ö±È¼´¿É¡£
¼òµ¥µÄ´æ´¢¹ý³Ì¿ÉÒÔÓÃÏòµ¼×Ô¶¯Éú³É£ºÔÚÆóÒµ¹ÜÀíÆ÷¹¤¾ßÀ¸µã»÷ÔËÐÐÏòµ¼Í¼±ê£¬µã»÷”Êý¾Ý¿â”¡¢”´´½¨´æ´¢¹ý³ÌÏòµ¼”¡£¸´ÔÓ´æ´¢¹ý³ÌµÄµ÷ÊÔ£ºÔÚ²éѯ·ÖÎöÆ÷×ó±ßµÄ¶ÔÏóä¯ÀÀÆ÷£¨Ã»ÓУ¿°´F8£©Ñ¡ÔñÒªµ÷ÊԵĴ洢¹ý³Ì,µãÓÒ¼ü£¬µãµ÷ÊÔ£¬ÊäÈë²ÎÊýÖ´ÐУ¬³öÏÖÒ»¸ö¸¡¶¯¹¤¾ßÌõ£¬ÉÏÃæÓе¥²½Ö´ÐУ¬¶ÏµãÉèÖõȡ£
Ò»¡¢²»ºÏÀíµÄË÷ÒýÉè¼Æ
----Àý£º±írecordÓÐ620000ÐУ¬ÊÔ¿´ÔÚ²»Í¬µÄË÷ÒýÏ£¬ÏÂÃ漸¸ö SQLµÄÔËÐÐÇé¿ö£º
---- 1.ÔÚdateÉϽ¨ÓÐÒ»·Ç¸öȺ¼¯Ë÷Òý
select count(*) from record where date >
'19991201' and date < '19991214'and amount >
2000 (25Ãë)
select date,sum(amount) from record group by date
(55Ãë)
select count(*) from record where date >
'19990901' and place in ('BJ','SH') (27Ãë)
---- ·ÖÎö£º
----dateÉÏÓдóÁ¿µÄÖظ´Öµ£¬ÔÚ·ÇȺ¼¯Ë÷ÒýÏ£¬Êý¾ÝÔÚÎïÀíÉÏËæ»ú´æ·ÅÔÚÊý¾ÝÒ³ÉÏ£¬ÔÚ
·¶Î§²éÕÒʱ£¬±ØÐëÖ´ÐÐÒ»´Î±íɨÃè²ÅÄÜÕÒµ½ÕâÒ»·¶Î§ÄÚµÄÈ«²¿ÐС£
---- 2.ÔÚdateÉϵÄÒ»¸öȺ¼¯Ë÷Òý
select count(*) from record where date >
'19991201' and date < '19991214' and amount >
2000 £¨14Ã룩
select date,sum(amount) from record group by date
£¨28Ã룩
select count(*) from record where date >
'19990901' and place in ('BJ','SH')£¨14Ã룩
---- ·ÖÎö£º
---- ÔÚȺ¼¯Ë÷ÒýÏ£¬Êý¾ÝÔÚÎïÀíÉÏ°´Ë³ÐòÔÚÊý¾ÝÒ³ÉÏ£¬Öظ´ÖµÒ²ÅÅÁÐÔÚÒ»Æð£¬Òò¶øÔÚ·¶
Χ²éÕÒʱ£¬¿ÉÒÔÏÈÕÒµ½Õâ¸ö·¶Î§µÄÆðÄ©µã£¬ÇÒÖ»ÔÚÕâ¸ö·¶Î§ÄÚɨÃèÊý¾ÝÒ³£¬±ÜÃâÁË´ó·¶
ΧɨÃ裬Ìá¸ßÁ˲éѯËٶȡ£
---- 3.ÔÚplace£¬date£¬amountÉϵÄ×éºÏË÷Òý
select count(*) from record where date >
'19991201' and date < '19991214' and amount >
2000 £¨26Ã룩
select date,sum(amount) from record group by date
£¨27Ã룩
select count(*) from record where date &g
Ïà¹ØÎĵµ£º
ÈçºÎÁ¬½Óµ½Áíһ̨»úÆ÷ÉϵÄsql server 2005
Ò»¡¢Òª½øÐÐÁ½¸öµØ·½µÄÉèÖÃ
1 µã¿ªÊ¼—³ÌÐò—sql server 2005 –ÅäÖù¤¾ß—sql server 2005Ó¦ÓÃÅäÖÃÆ÷ ,Èçͼ£º
Ñ¡±¾µØÁ¬½ÓºÍÔ¶³ÌÁ¬½ÓÖÐµÄ ½öʹÓÃtcp/ip»ò& ......
SQLÓïÑÔÓÉÃüÁî¡¢×Ӿ䡢ÔËËãºÍ¼¯ºÏº¯ÊýµÈ¹¹³É¡£ÔÚSQLÖУ¬Êý¾Ý¶¨ÒåÓïÑÔDDL£¨ÓÃÀ´½¨Á¢¼°¶¨ÒåÊý¾Ý±í¡¢×Ö¶ÎÒÔ¼°Ë÷ÒýµÈÊý¾Ý¿â½á¹¹£©°üº¬µÄÃüÁîÓÐCREATE¡¢DROP¡¢ALTER£»Êý¾Ý²Ù×ÝÓïÑÔDML£¨ÓÃÀ´ÌṩÊý¾ÝµÄ²éѯ¡¢ÅÅÐòÒÔ¼°É¸Ñ¡Êý¾ÝµÈ¹¦ÄÜ£©°üº¬µÄÃüÁîÓÐSELECT¡¢INSERT¡¢UPDATE¡¢DELETE¡£
Ò»¡¢SQLÓï¾ä
£¨1£©Select ²éѯÓï¾ä
Óï ......
¶þ¡¢ÒÔÐβεÄÐÎʽ¶¨ÒåºÍʹÓüǼ¡¢¶ÔÏóÀàÐÍ
ÔÚÓÃ×÷ÐÎʽ²ÎÊýʱ£¬¼Ç¼ÀàÐͺͶÔÏóÀàÐÍÓкܶàÏà֮ͬ´¦¡£ÔÚ½«ËüÃÇ×÷ΪÓαꡢº¯Êý»ò¹ý³ÌµÄÐÎʽ²ÎÊýÒÔÇ°£¬ÊÂÏȶ¼±ØÐ붨ÒåÒ»¸ö¼Ç¼ÀàÐÍ»òÕ߶ÔÏóÀàÐÍ¡£
ÈçÏÂÀýËùʾ£º
¼Ç¼
DECLARE
-- Define a record type.
TYPE individual_record IS RECORD
(individual_id ......
ËÄ¡¢ÁªºÏÊý×éµÄʹÓ÷½·¨
ÁªºÏÊý×éÒÔÇ°±»³ÆΪPL/SQL±í¡£ÔÚ±íÖв»ÄÜʹÓÃÁªºÏÊý×飬ֻÄܽ«ËüÃÇÓÃ×÷³ÌÐòÉè¼ÆµÄ½á¹¹Ìå¡£Ö»ÄÜÔÚPL/SQLÖзÃÎÊÁªºÏÊý×é¡£
×¢Òâµ½ÁªºÏÊý×é´øÀ´µÄһЩ¹Ø¼üÎÊÌâÊǷdz£ÖØÒªµÄ¡£ÕâЩÎÊÌâʹÎÒÃǽéÉÜËüÃǵÄÓ÷¨Ê±£¬ÐèÒª²ÉȡһЩÌرðµÄ·½·¨¡£ÕâЩÎÊÌâ°üÀ¨£º
ÁªºÏÊý×é²»ÐèÒª³õʼ»¯£¬Ò²Ã»Óй¹Ô캯ÊýÓï·¨¡£ÔÚ ......
SQLÓï¾äÏÈǰдµÄʱºò£¬ºÜÈÝÒ×°ÑһЩÌØÊâµÄÓ÷¨Íü¼Ç£¬ÎÒÌØ´ËÕûÀíÁËÒ»ÏÂSQLÓï¾ä²Ù×÷£¬·½±ã×Ô¼ºÐ´SQLʱ·½±ãÒ»µã£¬ÏëÌùÉÏÀ´£¬Ò»Æð¿´¿´£¬Í¬Ê±Ï£Íû´ó¼ÒÄܹ²Í¬¶à¶àÌáÒâ¼û£¬Ò²¸øÎÒÁôһЩ¸üºÃµÄ¼Ñ¾ä£¬ÕûÀíÒ»·Ý¡¶¾«ÃîSQLËÙ²éÊֲᡷ£¬²»Áߴͽ̣¡
Ò»¡¢»ù´¡
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾ ......