SQL Serverº¯Êý´óÈ«
--¾ÛºÏº¯Êý
use pubs
go
select avg(distinct price) --Ëãƽ¾ùÊý
from titles
where type='business'
go
use pubs
go
select max(ytd_sales) --×î´óÊý
from titles
go
use pubs
go
select min(ytd_sales) --×îСÊý
from titles
go
use pubs
go
select type,sum(price),sum(advance) --ÇóºÍ
from titles
group by type
order by type
go
use pubs
go
select count(distinct city) --Çó¸öÊý
from authors
go
use pubs
go
select stdev(royalty) --·µ»Ø¸ø¶¨±í´ïʽÖÐËùÓÐÖµµÄͳ¼Æ±ê׼ƫ²î
from titles
go
use pubs
go
select stdevp(royalty) --·µ»Ø±í´ïʽÖÐËùÓÐÖƵÄÌî³äͳ¼Æ±ê׼ƫ²î
from titles
go
use pubs
go
select var(royalty) --·µ»ØËùÓÐÖµµÄͳ¼Æ·½²î
from titles
go
use pubs
go
select varp(royalty) --·µ»ØËùÓÐÖµµÄÌî³äµÄͳ¼Æ·½²î
from titles
go
--Êýѧº¯Êý
select sin(23.45),atan(1.234),rand(),PI(),sign(-2.34) --ÆäÖÐrandÊÇ»ñµÃÒ»¸öËæ»úÊý
--
ÅäÖú¯Êý
SELECT @@VERSION --»ñÈ¡µ±Ç°Êý¾Ý¿â°æ±¾
SELECT @@LANGUAGE --µ±Ç°ÓïÑÔ
--
ʱ¼äº¯Êý
select getdate() as 'wawa_getdate' --µ±Ç°Ê±¼ä
select getutcdate() as 'wawa_getutcdate' --»ñÈ¡utcʱ¼ä
select day(getdate()) as 'wawa_day' --È¡³öÌì
select month(getdate()) as 'wawa_month' --È¡³öÔÂ
select year(getdate()) as 'wawa_year' --È¡³öÄê
select dateadd(d,3,getdate()) as wawa_dateadd --¼ÓÈýÌì,×¢Òâ'd'±íʾÌì,'m'±íʾÔÂ,'yy'±íʾÄê,ÏÂÃæÒ»Ñù
select datediff(d,'2004-07-01','2004-07-15') as wawa_datediff --¼ÆËãÁ½¸öʱ¼äµÄ²î
select datename(d,'2004-07-15') as wawa_datename --È¡³öʱ¼äµÄijһ²¿·Ö
select datepart(d,getdate()) as wawa_
Ïà¹ØÎĵµ£º
ÔÚEssbaseÖÐʹÓÃMDXÖ»ÄÜÓÃÓÚ²éѯ£¬Éв»ÄÜÀ´²Ù×÷Cube£¨MS SSASÖпÉÒÔʹÓÃMDXÀ´²Ù×÷CubeµÄ£©£¬ËùÒÔÕâÀïֻѧϰMDXµÄSelectÓï¾ä¡£
ÔÚѧϰµÄ¹ý³ÌÖУ¬ÎÒ¾õµÃ×îÓÐÄѶȵĵط½ÓÐÁ½¸ö¡£
Ò»ÊÇ£¬¶ÔOLAP¶àάµÄÀí½â¡£ÈçͬѧϰSQLÒ»Ñù£¬SQL×÷ÓõĶÔÏóÊÇ±í£¬±íµÄ½á¹¹¶¼ÊǶþάµÄ£¬±êʶÐÐÁм´¿É£»µ«ÊÇMDX×÷ÓõĶÔÏóÊǶàάÊý¾Ý¿â£¬ÄÇ ......
ÎÊÌâ:
Äú¹¤×÷µÄ±¾»ú×°ÓÐVisual Studio 2005£¬¾ÖÓòÍøÖÐÓÐһ̨SQL Server 2005Êý¾Ý¿â·þÎñÆ÷£¬ÄãÏëͨ¹ý±¾»úÔ¶³Ìµ÷ÊÔSQL Server 2005·þÎñÆ÷ÉϵĴ洢¹ý³Ì¡£µ«ÊDz»ÖªµÀÈçºÎÅäÖûòÆôÓÃÔ¶³Ìµ÷ÊÔ£¿Ï£ÍûÕâƪÎÄÕ¶ÔÄúÓÐÓ᣶ÔÓÚÊý¾Ý¿âºÍVisual StudioÔÚͬһ»úÆ÷µÄ´æ´¢¹ý³Ìµ÷ÊÔ£¬Ô°×ÓÀïÒѾÓÐһƪÒë×÷˵µÄºÜºÃÁË£¬¿ ......
-- Sql Get Last Day of Month...
SELECT (CASE MONTH(GETDATE())
WHEN 1 THEN 31
&nbs ......
SQL Server 2008 ¸´ÖÆ ·ÖÇøSWITCHÇåÀíÊý¾Ý
³¡¾°£º
ijÖÖÌض¨ÒµÎñÏ£¬ÎÒÃǵIJ¿·ÖÒµÎñÊý¾Ý¿ÉÄÜÖ»»á±£Áô±È½Ï¶ÌµÄʱ¼ä£¬ÓÃÀ´×öÁÙʱ´¦Àí¡£ÒòΪ¿¼ÂǸ߿ÉÓõÄÌØÐÔ£¬¿ÉÄÜ»áÀûÓÃ
SQL ServerµÄ¸´ÖÆ×é¼þ¸´ÖÆÕâÖÖÊý¾Ýµ½ÁíÍâµÄ ÀàËÆÇ°¶Ë£¬²éѯÖÐÐĵÈÊý¾Ý¿â·þÎñÆ÷£¬´´½¨Ò»¸öÈßÓั±¾¡£¸´ÖÆ×é¼þ±ê¼ÇÊÂÎñÈÕÖ¾£¬×·×ÙËùÓеÄUpdate£¬In ......
1½«sqlÖÐʹÓõÄһЩÌØÊâ·ûºÅ£¬Èç' -- /* ; %µÈÓÃReplace()¹ýÂË£»
2ÏÞÖÆÎı¾¿òÊäÈë×Ö·ûµÄ³¤¶È£»
3¼ì²éÓû§ÊäÈëµÄºÏ·¨ÐÔ£»¿Í»§¶ËÓë·þÎñÆ÷¶Ë¶¼ÒªÖ´ÐУ¬¿ÉÒÔʹÓÃÕýÔò¡£
4ʹÓôø²ÎÊýµÄSQLÓï¾äÐÎʽ¡£
ASP.NETÖÐÈçºÎ·À·¶SQL×¢Èëʽ¹¥»÷
Ò»¡¢Ê²Ã´ÊÇSQL×¢Èëʽ¹¥»÷£¿
¡¡¡¡ËùνSQL×¢Èëʽ¹¥»÷£¬¾ÍÊǹ¥»÷Õß°Ñ ......