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

sqlÐÐתÁÐ


дһ¸ö´æ´¢¹ý³Ì£¬½«±íÒ»°´ÕÕ±í¶þµÄÐÎʽ½øÐвéѯ¡£
²Ö¿âÃû³Æ ÉÌÆ·Ãû³Æ ÊýÁ¿
A
S001 12
A S002 17
A
S003 10
B S001 21
B
S002 5
B S003 0

C S001 100
C S002 11
C S003 25
(±íÒ»)
ÉÌ
Æ·Ãû³Æ ×Ü¿â´æ A B C
S001 133 12 21 100
S002 33 17 5 11
S003 35 10 0
25
£¨±í¶þ£©
create

table
tb(²Ö¿âÃû³Æ
varchar
(
10
),ÉÌÆ·Ãû³Æ
varchar
(
10
),ÊýÁ¿
int
)
insert

into
tb
values
(
'
A
'
,
'
S001
'
,
12
)
insert

into
tb
values
(
'
A
'
,
'
S002
'
,
17
)
insert

into
tb
values
(
'
A
'
,
'
S003
'
,
10
)
insert

into
tb
values
(
'
B
'
,
'
S001
'
,
21
)
insert

into
tb
values
(
'
B
'
,
'
S002
'
,
5
)
insert

into
tb
values
(
'
B
'
,
'
S003
'
,
0
)
insert

into
tb
values
(
'
C
'
,
'
S001
'
,
100
)
insert

into
tb
values
(
'
C
'
,
'
S002
'
,
11
)
insert

into
tb
values
(
'
C
'
,
'
S003
'
,
25
)
go
--
Èç¹ûÖ»ÓÐA£¬B£¬C£¬ÔòʹÓþ²Ì¬SQL¡£
select
ÉÌÆ·Ãû³Æ,

sum
(ÊýÁ¿) ×Ü¿â´æ,

sum
(
case
²Ö¿âÃû³Æ
when

'
A
'

then
ÊýÁ¿
else

0

end
)
[
A
]
,

sum
(
case
²Ö¿âÃû³Æ
when

'
B
'

then
ÊýÁ¿
else

0

end
)
[
B
]
,

sum
(
case
²Ö¿âÃû³Æ
when

'
C
'

then
ÊýÁ¿
else

0

end
)
[
C
]
from
tb
group

by
ÉÌÆ·Ãû³Æ
/*
ÉÌÆ·Ãû³Æ ×Ü¿â´æ A B C
---------- ----------- ----------- ----------- -----------
S001 133 12 21 100
S002 33


Ïà¹ØÎĵµ£º

SQL Server ¹ÜÀí³£ÓõÄSQLºÍT SQL

1. ²é¿´Êý¾Ý¿âµÄ°æ±¾  
  select @@version
 
  ³£¼ûµÄ¼¸ÖÖSQL SERVER´ò²¹¶¡ºóµÄ°æ±¾ºÅ:
 
  8.00.194   Microsoft SQL Server 2000
  8.00.384   Microsoft SQL Server 2000 SP1
  8.00.532   Microsoft SQL Server 2000 SP2
  8.00.760 &nb ......

sql·ÖÒ³£¨×ª£©

½¨Á¢Ò»¸ö Web Ó¦Ó㬷ÖÒ³ä¯ÀÀ¹¦Äܱز»¿ÉÉÙ¡£Õâ¸öÎÊÌâÊÇÊý¾Ý¿â´¦ÀíÖÐÊ®·Ö³£¼ûµÄÎÊÌâ¡£¾­µäµÄÊý¾Ý·ÖÒ³·½·¨ÊÇ:ADO ¼Í¼¼¯·ÖÒ³·¨£¬Ò²¾ÍÊÇÀûÓÃADO×Ô´øµÄ·ÖÒ³¹¦ÄÜ£¨ÀûÓÃÓα꣩À´ÊµÏÖ·ÖÒ³¡£µ«ÕâÖÖ·ÖÒ³·½·¨½öÊÊÓÃÓÚ½ÏСÊý¾ÝÁ¿µÄÇéÐΣ¬ÒòΪÓα걾ÉíÓÐȱµã£ºÓαêÊÇ´æ·ÅÔÚÄÚ´æÖУ¬ºÜ·ÑÄÚ´æ¡£ÓαêÒ»½¨Á¢£¬¾Í½«Ïà¹ØµÄ¼Ç¼Ëøס£¬Ö±µ½È¡ÏûÓ ......

SQL ÃæÊÔÌâ Ò»

ÌâÄ¿Ò»£º
 ÓÐÁ½ÕÅ±í£º²¿Ãűídepartment  ²¿ÃűàºÅdept_id  ²¿ÃÅÃû³Ædept_name            
               Ô±¹¤±íemployee     Ô±¹¤±àºÅemp_id ......

sql server 2000 Êý¾Ý±íµÄ ¹Ø¼ü×Ö

create table "user" (
   id                   int                  identity,
   constraint PK_USER prim ......

¼òµ¥µÄSQLÃæÊÔÌâ

1. Q. What is a join?
   A. Join is a process of retrieve pieces of data from different sets (tables) and returns them to the user or program as one joined collection of data.
2. Q. Can a table have more than one foreign key defined?
   A. A table can have any number of foreig ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ