SQL Server 2005ÖеÄT SQLÔöÇ¿C
ͨÓñí±í´ïʽ Common Table Expressions
ͨÓñí±í´ïʽ£¨CTE£©ÊÇÒ»¸ö¿ÉÒÔÓɶ¨ÒåÓï¾äÒýÓõÄÁÙʱ±íÃüÃûµÄ½á¹û¼¯¡£ÔÚËûÃǵļòµ¥ÐÎʽÖУ¬Äú¿ÉÒÔ½«CTEÊÓΪÀàËÆÓÚÊÓͼºÍÅÉÉú±í»ìºÏ¹¦ÄܵĸĽø°æ±¾¡£ÔÚ²éѯµÄfrom×Ó¾äÖÐÒýÓÃCTEµÄ·½Ê½ÀàËÆÓÚÒýÓÃÅÉÉú±íºÍÊÓͼµÄ·½Ê½¡£Ö»Ð붨ÒåCTEÒ»´Î£¬¼´¿ÉÔÚ²éѯÖжà´ÎÒýÓÃËü¡£ÔÚCTEµÄ¶¨ÒåÖУ¬¿ÉÒÔÒýÓÃÔÚͬһÅú´¦ÀíÖж¨ÒåµÄ±äÁ¿¡£µ«ÊÇCTEµÄÕæÕýÍþÁ¦ÔÚÓÚËüÃǵĵݹ鹦ÄÜ£¬¼´CTE¿ÉÒÔ°üº¬¶ÔËüÃÇ×ÔÉíµÄÒýÓá£
ÊÓͼ¡¢ÅÉÉú±íºÍCTEÄÚ²¿µÄ²éѯµÄÒ»°ãÐÎʽ
1¡¢ÊÓͼ
CREATE VIEW <view_name>(<column_aliases>) AS <view_query>
2¡¢ÅÉÉú±í
SELECT * from (<derived_table)query>) AS <dericed_table_alias>(<column_aliases>)
3¡¢CTE
WITH <cte_alias>(<column_aliases>)
AS
{
<cte_query>
)
SELECT * from <cte_alias]>
Ôڹؼü×ÖWITHÖ®ºó£¬ÎªCTEÌṩһ¸ö±ðÃû£¬²¢ÇÒΪËüµÄ½á¹ûÁÐÌṩһ¸ö¿ÉÑ¡µÄ±ðÃûÁÐ±í£»±àдCTEµÄÖ÷Ì壻Ȼºó´ÓÍⲿ²éѯÖÐÒýÓÃËü¡£
with aa(id1,id2 )
as
(select xsrq,count(spbm)
from ecv_saledetail where xsrq>='2010-01-01' and xsrq<='2010-01-10'
group by xsrq)
select * from aa
Ïà¹ØÎĵµ£º
±¾ÎÄ×ªÔØÓÚ£ºhttp://www.javaeye.com/topic/185385
ѧϰÊý¾Ý¿â²éѯµÄʱºò¶Ô¶à±íÁ¬½Ó²éѯµÄÓÐЩ¸ÅÄ±È½ÏÄ£ºý¡£¶øÁ¬½Ó²éѯÊÇÔÚÊý¾Ý¿â²éѯ²Ù×÷µÄʱºò¿Ï¶¨ÒªÓõ½µÄ¡£¶ÔÓڴ˸ÅÄî
ÎÒÓÃͨË×һЩµÄÓïÑÔºÍÀý×ÓÀ´½øÐн²½â¡£Õâ¸öÀý×ÓÊÇÎÒ½²¿ÎµÄʱºò¾³£²ÉÓõÄÀý×Ó¡£
Ê×ÏÈÎÒÃÇ×öÁ½ÕÅ±í£ºÔ±¹¤ÐÅÏ¢±íºÍ²¿ÃÅÐÅÏ¢±í£¬ÔÚ´Ë£¬±íµ ......
ǰһƪ²©¿Í IP to Integer ÌṩµÄ SQL º¯ÊýÊÇ IP ת»»³É Integer µÄ·½·¨¡£ Integer µÄ×î´óֵΪ£º 2147483647£¨2^31 - 1£©¡£°´ÕÕ IP ת»»³ÉÕûÊýµÄËã·¨£¬»áËã³öÀ´´óÓÚÕâ¸öÖµµÄ£¬ËùÒÔ֮ǰÌṩµÄ IP ת»»³É Integer µÄ·½·¨»áËã³ö¸ºÖµ¡£ ÏÂÃæÊÇ IP to BigInt µÄת»»Ëã·¨£¬ ÕâʱºòÔËËã¾Í²»»áСÓÚÁã¡£
CREATE FUNCTION dbo.ipS ......
Microsoft SQL server2000ÓÉһϵÁÐÏ໥Ð×÷µÄ×é¼þ¹¹³É¡£ÄÜÂú×ã×î´óµÄWEBÕ¾µãºÍÆóÒµÊý¾Ý´¦Àíϵͳ´æ´¢ºÍ·ÖÎöÊý¾ÝµÄÐèÒª¡£±¾ÎÄ´øÀ´µÄ¾ÍÊÇÔÚwindows»·¾³ÏÂSQL2000µÄ°²×°¹ý³Ì¡£
ϵͳÐèÇó
ÕâÀïÒÔÆäËĺÏÒ»°æ±¾ÎªÀý£¬ÒÔϰ²×°¹ý³ÌͬÀí¡£Microsoft SQL Server 2000 ¿ÉÔÚÔËÐÐ Intel»ò¼æÈÝµÄ Pentium¡¢Pentium Pr ......
SQL ServerʹÓñê×¼B-Ê÷´æ´¢ÐÅÏ¢¡£
Ë÷ÒýÖмä²ã´ÎÊýÓɱíµÄÐÐÊýºÍË÷ÒýÐеĴóС¾ö¶¨¡£ÈôʹÓÃÒ»¸ö½Ï³¤µÄ¼ü£¨key£©À´´´½¨Ë÷Òý£¬Ò»¸ö·ÖÒ³ÉϾÍÖ»ÄÜÈÝÄɽÏÉÙµÄÌõÄ¿£¬¼´Ê÷µÄ²ã´Î¿ÉÄÜ»áÔö¶à¡£
¶ÔÓÚÈκÎË÷Òý£¨ÎÞÂÛÊǾۼ¯»ò·Ç¾Û¼¯Ë÷Òý£©£¬Ë÷ÒýB-Ê÷µÄÒ¶¼¶½Úµã°üº¬Ë÷ÒýµÄ¼üÖµ£¬²¢¶¼°´ÕÕ¼üµÄ˳ÐòÅÅÁС£¾Û¼¯ºÍ·Ç¾Û¼¯Ë÷ÒýµÄÇø±ðÔÚÓÚÒ¶¼¶½Úµ ......
1¡¢²é¿´±í¿Õ¼äµÄÃû³Æ¼°´óС
¡¡¡¡select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
¡¡¡¡from dba_tablespaces t, dba_data_files d
¡¡¡¡where t.tablespace_name = d.tablespace_name
¡¡¡¡group by t.tablespace_name;
¡¡¡¡
¡¡¡¡2¡¢²é¿´±í¿Õ¼äÎïÀíÎļþµÄÃû³Æ¼°´óС
¡¡¡¡select tablespace_ ......