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

SQLÃæÊÔÌ⣨תÔØ£©

SQLÃæÊÔÌ⣨1£©
create table testtable1
(
id int IDENTITY,
department varchar(12)
)
select * from testtable1
insert into testtable1 values('Éè¼Æ')
insert into testtable1 values('Êг¡')
insert into testtable1 values('ÊÛºó')
/*
½á¹û
id department
1   Éè¼Æ
2   Êг¡
3   ÊÛºó
*/
create table testtable2
(
id int IDENTITY,
dptID int,
name varchar(12)
)
insert into testtable2 values(1,'ÕÅÈý')
insert into testtable2 values(1,'ÀîËÄ')
insert into testtable2 values(2,'ÍõÎå')
insert into testtable2 values(3,'ÅíÁù')
insert into testtable2 values(4,'³ÂÆß')
/*
ÓÃÒ»ÌõSQLÓï¾ä£¬ÔõôÏÔʾÈçϽá¹û
id dptID department name
1   1      Éè¼Æ        ÕÅÈý
2   1      Éè¼Æ        ÀîËÄ
3   2      Êг¡        ÍõÎå
4   3      ÊÛºó        ÅíÁù
5   4      ºÚÈË        ³ÂÆß
*/
´ð°¸£º
SELECT testtable2.* , ISNULL(department,'ºÚÈË')
from testtable1 right join testtable2 on testtable2.dptID = testtable1.ID
Ò²×ö³öÀ´Á˿ɱÈÕâ·½·¨ÉÔ¸´ÔÓ¡£
sqlÃæÊÔÌ⣨2£©
ÓбíA£¬½á¹¹ÈçÏ£º
A: p_ID p_Num s_id
1 10 01
1 12 02
2 8 01
3 11 01
3 8 03
ÆäÖУºp_IDΪ²úÆ·ID£¬p_NumΪ²úÆ·¿â´æÁ¿£¬s_idΪ²Ö¿âID¡£ÇëÓÃSQLÓï¾äʵÏÖ½«ÉϱíÖеÄÊý¾ÝºÏ²¢£¬ºÏ²¢ºóµÄÊý¾ÝΪ£º
p_ID s1_id s2_id s3_id
1 10 12 0
2 8 0 0
3 11 0 8
ÆäÖУºs1_idΪ²Ö¿â1µÄ¿â´æÁ¿£¬s2_idΪ²Ö¿â2µÄ¿â´æÁ¿£¬s3_idΪ²Ö¿â3µÄ¿â´æÁ¿¡£Èç¹û¸Ã²úÆ·ÔÚij²Ö¿âÖÐÎÞ¿â´æÁ¿£¬ÄÇô¾ÍÊÇ0´úÌæ¡£
½á¹û£º
select p_id ,
sum(case when s_id=1 then p_num else 0 end) as s1_id
,sum(case when s_id=2 then p_num else 0 end) as s2_id
,sum(case when s_id=3 then p_num else 0 end) as s3_id
from myPro group by p_id
SQLÃæÊÔÌ⣨3£©
1£®´¥·¢Æ÷µÄ×÷Óã¿
  ´ð£º´¥·¢Æ÷ÊÇÒ»ÖÐÌØÊâµÄ´æ´


Ïà¹ØÎĵµ£º

Tips on Optimizing SQL Server Clustered Indexes

http://www.sql-server-performance.com/tips/clustered_indexes_p1.aspx
As a rule of thumb, every table should have a clustered index. Generally, but not always, the clustered index should be on a column that monotonically increases--such as an identity column, or some other column where the value is ......

textareaÖеÄÄÚÈÝͨ¹ýÌí¼Ó°´Å¥Ìí¼Óµ½SQLÊý¾Ý¿âÖÐ

ÎÒ¶¨ÒåÁËÒ»¸ö textarea:
  <tr bgcolor="#CCCCCC" align="center" valign="bottom">
            <td align="right" valign="top" class="style1"  >ÎÄÕÂÄÚÈÝ£º</td>
         &nbs ......

ÈýÖÖSQL·ÖÒ³Óï¾ä

À´×Ô£ºhttp://www.cnblogs.com/morningwang/archive/2009/01/02/1367277.html
ÓйطÖÒ³ SQL µÄ×ÊÁϺܶ࣬ÓеÄʹÓô洢¹ý³Ì£¬ÓеÄʹÓÃÓαꡣ±¾È˲»Ï²»¶Ê¹ÓÃÓα꣬ÎÒ¾õµÃËüºÄ×Ê¡¢Ð§Âʵͣ»Ê¹Óô洢¹ý³ÌÊǸö²»´íµÄÑ¡Ôñ£¬ÒòΪ´æ´¢¹ý³ÌÊǾ­¹ýÔ¤±àÒëµÄ£¬Ö´ÐÐЧÂʸߣ¬Ò²¸üÁé»î¡£ÏÈ¿´¿´µ¥Ìõ SQL Óï¾äµÄ·ÖÒ³ SQL °É¡£
·½·¨1£º
ÊÊÓÃ ......

sql serverÑ¡ÔñÁË»ìºÏģʽÎÊÌâ

sql serverÑ¡ÔñÁË»ìºÏģʽÎÊÌâ
ÒòΪҪѡÔñ»ìºÏģʽ²ÅÄÜʹÓÃsaÓû§µÇ¼µÄÎÊÌâ
È»ºóÆóÒµ¹ÜÀíÆ÷ÀïÃ澹ȻѡÁËÒÔºóûÓÐЧ¹û ÓÀÔ¶¶¼Êǽöwindowsģʽ
ÎÞÓï ²»¶ÏÖØÆômssql ÓÖÑ¡Ôñ »ìºÏģʽ  ´óÔ¼¼¸·ÖÖÓºó¾¹È»¿ÉÒÔÑ¡ÔñÁË
zhenTMD µÄÎÞÄΣ¡ ......

Excelµ¼ÈëSQL SERVERÖÐ

--Excelµ¼ÈëSQL SERVERÖÐ
--±í½á¹¹²»´æÔÚ¿ÉÒÔʹÓÃ
--ÆôÓÃAd Hoc Distributed Queries£º
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
select * into serv_user_bak1 from
OpenRowSet('microsoft.jet.oledb.4.0','Excel 8.0;HDR=yes;dat ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ