Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL ÐÐÁл¥×ª

--ÐÐÁл¥×ª
/******************************************************************************************************************************************************
ÒÔѧÉú³É¼¨ÎªÀý×Ó£¬±È½ÏÐÎÏóÒ׶®
ÕûÀíÈË£ºÖйú·ç(Roy)
ÈÕÆÚ:2008.06.06
******************************************************************************************************************************************************/
--1¡¢Ðл¥ÁÐ
--> --> (Roy)Éú³É測試數據
if not object_id('Class') is null
    drop table Class
Go
Create table Class([Student] nvarchar(2),[Course] nvarchar(2),[Score] int)
Insert Class
select N'ÕÅÈý',N'ÓïÎÄ',78 union all
select N'ÕÅÈý',N'Êýѧ',87 union all
select N'ÕÅÈý',N'Ó¢Óï',82 union all
select N'ÕÅÈý',N'ÎïÀí',90 union all
select N'ÀîËÄ',N'ÓïÎÄ',65 union all
select N'ÀîËÄ',N'Êýѧ',77 union all
select N'ÀîËÄ',N'Ó¢Óï',65 union all
select N'ÀîËÄ',N'ÎïÀí',85
Go
--2000·½·¨:
¶¯Ì¬:
declare @s nvarchar(4000)
set @s=''
Select     @s=@s+','+quotename([Course])+'=max(case when [Course]='+quotename([Course],'''')+' then [Score] else 0 end)'
from Class group by[Course]
exec('select [Student]'+@s+' from Class group by [Student]')
Éú³É¾²Ì¬:
select
    [Student],
    [Êýѧ]=max(case when [Course]='Êýѧ' then [Score] else 0 end),
    [ÎïÀí]=max(case when [Course]='ÎïÀí' then [Score] else 0 end),
    [Ó¢Óï]=max(case when [Course]='Ó¢Óï' then [Score] else 0 end),
    [ÓïÎÄ]=max(case when [Course]='ÓïÎÄ' then [Score] else 0 end)
from
    Class
group by [Student]
GO
¶¯Ì¬:
declare @s nvarchar(4000)
Select     @s=isnull(@s+',','')+quotename([Course]) from Class group by[Course]
exec('select * from Class pivot (max([Score]) for [Course] in('+@s+'))b')
Éú³É¾²Ì¬:
select *
from
    Class
pivot
    (max([Score]) for [Course] in([Êýѧ],[ÎïÀí],[Ó¢Óï],[ÓïÎÄ]))b


Ïà¹ØÎĵµ£º

AccessºÍSQL2000ÖÐÓï¾äµÄÇø±ð

1 £¬¶ÔÓÚÈÕÆÚ×Ö¶Î×Ö¶Î
access±íʾΪ£º#1981-28-12#
SQLSERVER2000±íʾΪ£º''1981-02-12''
2,SQLÓï¾äÇø±ð£¬select ,update ÔÚ¶Ôµ¥±í²Ù×÷ʱ¶¼²î²»¶à£¬
µ«¶à±í²Ù×÷ʱupdateÓï¾äµÄÇø±ðACCESSÓëSQLSERVERÖеÄUpdateÓï¾ä¶Ô±È:
SQLSERVERÖиüжà±íµÄUpdateÓï¾ä:
Update Tab1
SET a.Name = b.Name
from Tab1 a,Tab2 b
Whe ......

SQLSERVER SQLÐÔÄÜÓÅ»¯

1.Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)¡¡¡¡
¡¡¡¡ SQLSERVERµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬Òò´Ëfrom×Ó¾äÖÐдÔÚ×îºóµÄ±í£¨»ù´¡±ídriving table£©½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏ£¬±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í£¬µ±SQLSERVER´¦Àí¶à¸ö±íʱ£¬»áÔËÓÃÅÅÐò¼°ºÏ²¢µÄ·½Ê½Á ......

ZZ saµÇ½ʧ°Ü SQL Server´íÎó18456µÄ½â¾ö·½·¨

×òÌìÎÒµÄSQL£¨Microsoft SQL Server 2005 £©µÇ¼²»ÉÏÈ¥ÁË£¬Ô­À´ÊdzöÏÖÁ˼¸¸öСÎÊÌ⣬ÏÖÔڼǼһÏÂÎҵĽâ¾öÕ⼸¸öÇé¿öµÄ°ì·¨¡££¨½â¾ö·½·¨ÓкܶàÖÖ£¬ÕâЩֻÊÇÎҵĽâ¾ö·½·¨£¬½ö¹©²Î¿¼£©
²éÕÒÎÊÌâµÄ¹ý³Ì£º£¨×¢£ºÓÃwindowsÕ˺Ż¹ÊÇ¿ÉÒԵǼµÄ£©
µÚÒ»²½£º Æô¶¯ËùÓÐÓëSQLÓйصķþÎñ£¬ÎÊÌâÒÀ¾É£»
µÚ¶þ²½£º ²é¿´windows·À»ðǽ£ ......

sqlÓï¾äÓÅ»¯

²Ù×÷·ûÓÅ»¯
IN ²Ù×÷·û
ÓÃINд³öÀ´µÄSQLµÄÓŵãÊDZȽÏÈÝÒ×д¼°ÇåÎúÒ׶®£¬Õâ±È½ÏÊʺÏÏÖ´úÈí¼þ¿ª·¢µÄ·ç¸ñ¡£
µ«ÊÇÓÃINµÄSQLÐÔÄÜ×ÜÊDZȽϵ͵ģº
    Êý¾Ý¿âÊÔͼ½«Æäת»»³É¶à¸ö±íµÄÁ¬½Ó£¬Èç¹ûת»»²»³É¹¦ÔòÏÈÖ´ÐÐINÀïÃæµÄ×Ó²éѯ£¬ÔÙ²éѯÍâ²ãµÄ±í¼Ç¼£¬Èç¹ûת»»³É¹¦ÔòÖ±½Ó²ÉÓöà¸ö±íµÄÁ¬½Ó·½Ê½²éѯ¡£Óɴ˿ɼû ......

sql ·ÖÒ³¼¼Êõ

·ÖÒ³Óï¾ä
sqlserver ·½°¸1: select top 10 * from t where id not in(select top 30 id from t order by id) order by id
·½°¸2£º select top 10 * from t where id in (select top 40 id from t order by id)oder by id desc
mysql: select * from t order by id limit 30,10
oracle: select * from (select rownu ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ