²éѯ°à¼¶Öм°¸ñ£¬Ò»°ã£¬ÓÅÐãµÄÈËÊýµÄsqlÓï¾ä
select a.ClassName,a.CourseName,sum(²»¼°¸ñ) as ²»¼°¸ñ,sum(²î) as ²î,sum(ÖеÈ) as ÖеÈ,sum(ºÃ) as ºÃ ,sum(²»¼°¸ñ)+sum(²î)+sum(ÖеÈ)+sum(ºÃ) as °à¼¶×ÜÈËÊý from (select StudentID,ClassName,CourseName,1 as ²»¼°¸ñ,0 as ²î,0 as ÖеÈ,0 as ºÃ from StudentScore where ScoreRemark='fail' union all
select StudentID,ClassName,CourseName,0 as ²»¼°¸ñ,1 as ²î,0 as ÖеÈ,0 as ºÃ from StudentScore where ScoreRemark='low' union all
select StudentID,ClassName,CourseName,0 as ²»¼°¸ñ,0 as ²î,1 as ÖеÈ,0 as ºÃ from StudentScore where ScoreRemark='medium' union all
select StudentID,ClassName,CourseName,0 as ²»¼°¸ñ,0 as ²î,0 as ÖеÈ,1 as ºÃ from StudentScore where ScoreRemark='good' )a group by ClassName,CourseName
ÔÚÕâÀïÐèҪעÒâµÄÊÇÒª¸øijЩ×ֶμӱðÃûÒÔʾÇø±ð£¡
Ïà¹ØÎĵµ£º
¸ÅÊö
Microsoft SQL Server 2008 ÌṩÁËÓÐÖúÓÚÓÐЧ¹ÜÀí°²È«ÐÔ¹¦ÄÜÅäÖá¢Ç¿Éí·ÝÑéÖ¤ºÍ·ÃÎÊ¿ØÖƵݲȫÐÔÔöÇ¿¹¦ÄÜ¡¢¹¦ÄÜÇ¿´óµÄ¼ÓÃܺÍÃÜÔ¿¹ÜÀí¹¦ÄÜ£¬ÒÔ¼°ÔöÇ¿ÐÍÉóºË¹¦ÄÜ¡£
ÖØ´óµÄй¦ÄÜ
ʹÓûùÓÚ²ßÂԵĹÜÀí£¬Õë¶ÔÆóÒµÄÚµÄÊý¾ÝÀ´¹ÜÀí¼°¼ì²â²»·ûºÏ°²È«²ßÂÔµÄÇé¿ö
²»ÐèÐÞ¸ÄÓ¦ÓóÌÐò¼´¿ÉʹÓÃ͸Ã÷Êý¾Ý¼ÓÃÜÀ´¼ÓÃÜÊý¾Ý
ʹÓÿÉÀ© ......
Ëø¶¨Êý¾Ý¿âµÄÒ»¸ö±í
SELECT * from table WITH (HOLDLOCK)
×¢Òâ: Ëø¶¨Êý¾Ý¿âµÄÒ»¸ö±íµÄÇø±ð
SELECT * from table WITH (HOLDLOCK)
ÆäËûÊÂÎñ¿ÉÒÔ¶ÁÈ¡±í£¬µ«²»ÄܸüÐÂɾ³ý
SELECT * from table WITH (TABLOCKX)
ÆäËûÊÂÎñ²»ÄܶÁÈ¡±í,¸üкÍɾ³ý
SELECT Óï¾äÖГ¼ÓËøÑ¡ÏŦÄÜ˵Ã÷
SQL ServerÌṩÁËÇ¿´ó¶øÍ ......
дSQLµÄ±Èд.NET³ÌÐòµÄÌåÑéÉϲîÒ»µÈ£¬Ã»ÓÐÖÇÄÜÌáʾ£¬ÐèÒª¼Çס¹Ø¼ü×Ö£¬º¯Êý»òÕß²»¶ÏµØCopy±í×Ö¶ÎÃû£¬×Ô¶¨Ò庯Êý£¬´æ´¢¹ý³ÌÖ®ÀàµÄ¡£²»¹ýÔÚ
VS2010ÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃÖÇÄÜÌáʾÁË£¬ÈçÏÂÃ漸·ùͼËùʾ£º
ÔÚ±à¼Æ÷ÖУ¬ ÊäÈë Shift + J
£¨Ìáʾ£º VS2010 ¿ª·¢¹¤¾ßÖбêµÄÊÇ Ctrl +J ÆäʵӦ¸ÃÊÇ Shift + J £©¾Í¿ÉÒÔ×Ô¶¯´ò¿ªÕâ¸öÖÇ ......
inner join(µÈÖµÁ¬½Ó) Ö»·µ»ØÁ½¸ö±íÖÐÁª½á×Ö¶ÎÏàµÈµÄÐÐ
left join(×óÁª½Ó) ·µ»Ø°üÀ¨×ó±íÖеÄËùÓмǼºÍÓÒ±íÖÐÁª½á×Ö¶ÎÏàµÈµÄ¼Ç¼
right join(ÓÒÁª½Ó) ·µ»Ø°üÀ¨ÓÒ±íÖеÄËùÓмǼºÍ×ó±íÖÐÁª½á×Ö¶ÎÏàµÈµÄ¼Ç¼
INNER JOIN Óï·¨£º
INNER JOIN Á¬½ÓÁ½¸öÊý¾Ý±íµÄÓ÷¨£º
SELECT * from ±í1 INNER JOIN ±í2 ON ±í1.×ֶκÅ=±í2 ......
Êý¾ÝÀàÐÍ:
Ò»¡¢ ÕûÊýÊý¾ÝÀàÐÍ
INT(INTEGER) 4
SMALLINT 2
TINYINT 1
BIGINT & ......