sqlÖÐhaving Óëgroup byÏê½â
GROUP BY ʵÀý
±í "Sales":
Company Amount
W3Course 6500
IBM 5500
W3Course 7300
SQL:
SELECT Company, SUM(Amount) from Sales
½á¹û:
Company SUM(Amount)
W3Course 19300
IBM 19300
W3Course 19300
ÉÏÃæµÄ´úÂëÊÇÎÞЧµÄ£¬ÕâÊÇÓÉÓÚ±»·µ»ØµÄÁÐûÓнøÐв¿·ÖºÏ¼Æ¡£GROUP BY ×Ó¾äÄܽâ¾öÕâ¸öÎÊÌ⣺
SELECT Company,SUM(Amount) from Sales
GROUP BY Company
½á¹û:
Company SUM(Amount)
W3Course 13800
IBM 5500
HAVING...
°Ñ HAVING ¼ÓÈë SQL µÄÔÒòÊÇ£¬WHERE ÎÞ·¨Ó¦ÓÃÓںϼƺ¯Êý£¬¶øÈç¹ûûÓÐ HAVING£¬¾ÍÎÞ·¨²âÊÔ½á¹ûÌõ¼þ¡£
HAVING µÄÓï·¨:
SELECT column,SUM(column) from table
GROUP BY column
HAVING SUM(column) condition value
±í "Sales":
Company Amount
W3Course 6500
IBM 5500
W3Course 7300
SQL:
SELECT Company,SUM(Amount) from Sales
GROUP BY Company
HAVING SUM(Amount)>10000
½á¹û£º
Company SUM(Amount)
W3Course 13800
Ïà¹ØÎĵµ£º
ÈçºÎÈ·¶¨ËùÔËÐÐµÄ SQL Server 2005 µÄ°æ±¾
Ҫȷ¶¨ËùÔËÐÐµÄ SQL Server 2005 µÄ°æ±¾£¬ÇëʹÓà SQL Server Management Studio Á¬½Óµ½ SQL Server 2005£¬È»ºóÔËÐÐÒÔÏ Transact-SQL Óï¾ä£º
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
ÔËÐнá¹ûÈçÏ£º
²úÆ·° ......
SQL ServerÓëExcelÊý¾Ý»¥µ¼
´ÓSQL ServerÖе¼Èë/µ¼³ö Excel µÄ»ù±¾·½·¨
/*=================== µ¼Èë/µ¼³ö Excel µÄ»ù±¾·½·¨ ===================*/
´ÓExcelÎļþÖÐ,µ¼ÈëÊý¾Ýµ½SQLÊý¾Ý¿âÖÐ,ºÜ¼òµ¥,Ö±½ÓÓÃÏÂÃæµÄÓï¾ä:
/*========================================================*/
--Èç¹û½ÓÊÜÊý¾Ýµ¼ÈëµÄ±íÒѾ´æÔÚ
ins ......
Aaron Bertrand
Adam Machanic
All Things SQL Server
Allen Kinsel - SQL DBA
Allen White
Amit Bansal writes...
Andrew Fryer's Blog
Andrew Kelly
Andy Leonard
Anything and Everything IT
Arcane Code
Arnie Rowland: Ramblings of a Harried Technogeek
B.I. for the SQL Guy
Bart Duncan's SQL Weblog ......
declare @ID varchar(10)
set @ID=9 --¸ù½Úµã
declare @i int --¼¶Êý
declare @t table(ID varchar(10),ParentID varchar(10),Level int)
set @i = 1
insert into @t select @ID,0,0 --µ±Ç°¼¶£¬±¾¼¶£¬Èç¹û²»ÒªµÄ»°¿ÉÒÔ×¢Ê͵ô»òÔÙ¼Ó¸ö²ÎÊýÀ´Ñ¡Ôñ²Ù×÷
insert into @t select ID,ParentID,@i from t_ ......
SQL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database dbname ......