SQL¾µä×éºÏ²éѯ
´Ó²©¿ÍÔ°Öп´µ½Ò»ÆªÎÄÕ£¬½éÉÜ´óÈí¼þ¹«Ë¾ÃæÊÔʱ³£³£»á³öµÄÁ½µÀSQLÌ⣨¼û¸½Â¼£©¡£
ÎÒ¾õµÃÊÜÒæºÜ¶à£¬ÔÚ´Ë֮ǰ£¬ÎÒÒ»Ö±¾õµÃ£¬SQL2008ËÆºõÌṩÁËÕâ·½ÃæµÄÖ§³Ö£¬µ«¸üµÍµÄ°æ±¾£¬°üÀ¨2005£¬·ÇÓαê×ö²»³öÀ´£¨Ë®Æ½¹»²Ë£©¡£×ܽáÐĵÃÈçÏ£º
1¡¢ Ç¿´óµÄgroup by
1 select stdname,
2 isnull(sum( case stdsubject when ' »¯Ñ§ ' then Result end), 0 ) [»¯Ñ§],
3 isnull(sum( case stdsubject when ' Êýѧ ' then Result end), 0 ) [Êýѧ],
4 isnull(sum( case stdsubject when ' ÎïÀí ' then Result end), 0 ) [ÎïÀí],
5 isnull(sum( case stdsubject when ' ÓïÎÄ ' then Result end), 0 ) [ÓïÎÄ]
6 from #student
7 group by stdname
ÔÚÕâÀgroup byÓësum + case½áºÏ£¬¿ÉÒÔ½«±í1ÖеļǼ£¨ÐУ©±ä³É±í2µÄ×ֶΣ¨ÁУ©¡£SumÀïÃæÈç¹ûûÓÐcase£¬ÄÇô³öÀ´µÄÖµ£¬Ö»ÄÜÊÇÈ«²¿¿ÆÄ¿µÄ×ܺͣ¬ÓÃÁËcaseÒÔºó£¬¾Í ÊÇij¿ÆµÄ³É¼¨£»È»ºóÕâÀïÓÃÁ˺ü¸¸ösum£¬Ã¿¸ö¿ÆÄ¿Ò»¸ösum£¬ÓÚÊDZí1Öб¾À´Ä³ÈËij¿ÆÕ¼Ò»Ìõ¼Ç¼µÄ“ÐД¾Í±ä³ÉÁ˱í2ÀïijÈËÒ»Ìõ¼Ç¼£¬Ã¿¿Æ×öÒ»¸ö×Ö¶Î ÁË¡£
ÕâÖÖÐÄ˼ÇÉÃîºÍ¶ÔÓï·¨µÄÊìÁ·ÔËÓÃÈÃÈË»÷½ÚÔÞ̾¡£
2¡¢ ÀûÓÃselect from (select from)µÄģʽÉú³ÉSQLÓï¾ä
1 declare @sql varchar( 4000 )
2 set @sql = ' select stdname '
3 select @sql = @sql + ' ,isnull(sum(case stdsubject when ''' + stdsubject + ''' then Result end),0) [ ' + stdsubject + ' ] '
4 from (select distinct stdsubject from #student) as a
5 select @sql = @sql + ' from #student group by stdname '
6 print @sql
7 exec(@sql)
ΪÁË×Ô¶¯Ð´ÉÏËùÓеĿÆÄ¿£¬ÕâÀïÏȽ«¿ÆÄ¿ÐÅÏ¢ÌáÁ¶³öÀ´£º
4 from (select distinct stdsubject from #student) as &
Ïà¹ØÎĵµ£º
ÎÊÌâ±³¾°£º
¡¡¡¡ÈÕ³£¶ÔSql Server 2005¹ØÏµÊý¾Ý¿â½øÐвÙ×÷ʱ£¬ÓÐʱ¶ÔÊý¾Ý¿â£¨È磺SharepointÍøÕ¾ÅäÖÃÊý¾Ý¿âÃû
Sharepoint_Config£©½øÐÐЩ²»Õý³£²Ù×÷ÈçÊý¾Ý¿âÔÚ¶Áдʱ¶øÎÞ¹ÊÍ£Ö¹Êý¾Ý¿â£¬´Ó¶øµ¼ÖÂSql Server 2005Êý¾Ý¿â²»Õý³£
Öжϣ¬µ±Ôٴδò¿ªÊý¾Ý¿âʱ»á·¢ÏÖijЩÊý¾Ý¿â»á±»±ê¼ÇΪ“¿ÉÒÉ”£¨suspect)£¬¼´ÔÚÊý¾ ......
ת×Ô£º http://hi.baidu.com/beanchx/blog/item/ed056509d66f65cc3bc763f4.html
p6spyµÄÌæ´úÆ·£ºjdbc logger
2007Äê09ÔÂ13ÈÕ ÏÂÎç 01:07
Ê×ÏȽéÉÜÒ»ÏÂÕâ¸ö¿ªÔ´µÄÏîÄ¿¡£Õâ¸öÊÇÒ»¸ö¶ÔjdbcÖеÄsql½øÐÐloggerµÄÒ»¸ö¹¤¾ß¡£ÈôÔÚÏîÄ¿ÖвÉÓÃÁ˽϶àµÄpreparedStatement£¬ÄÇô´òÓ¡³öÀ´µÄsql»áÓкܶà"?"£¬·Ç³£²»·½±ã¡£ÓÐÒ»¸ö²úƷΪp ......
SQL ServerÁ¬½ÓÔ¶³ÌÊý¾ÝÔ´µÄ»ù±¾·½·¨ÓÐÏÂÃæÈýÖÖ£º
OPENDATASOURCE
: The OPENDATASOURCE function is used to
specify connection information for a remote data source by specifying
the OLE DB provider and an initialization string. OPENDATASOURCE can be
used directly within a SELECT, INSERT, UPDATE, or ......
Ö´ÐÐ Êý¾Ý¿â²éѯʱ£¬ÓÐÍêÕû²éѯºÍÄ£ºý²éѯ֮·Ö¡£
Ò»°ãÄ£ºýÓï¾äÈçÏ£º
SELECT ×Ö¶Î from ±í WHERE ij×Ö¶Î Like Ìõ¼þ
ÆäÖйØÓÚÌõ¼þ£¬SQLÌṩÁËËÄÖÖÆ¥Åäģʽ£º
1£¬%£º±íʾÈÎÒâ0¸ö»ò¶à¸ö×Ö·û¡£¿ÉÆ¥ÅäÈÎÒâÀàÐͺͳ¤¶ÈµÄ×Ö·û£¬ÓÐЩÇé¿öÏÂÈôÊÇÖÐÎÄ£¬ÇëÔËÓÃÁ½¸ö°Ù·ÖºÅ£¨%%£©±íʾ¡£
±ÈÈç SELECT * from [user] WHERE u_na ......
SQL Server ·ÖÒ³
½¨Á¢±í£º
CREATE TABLE [TestTable] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[FirstName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[LastName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[Country] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Note] [nvarchar ......