sqlserver多表查詢
Ⅰ sqlserver 同時查詢多表數據
在sqlserver中新建個視圖,很直觀看,相查哪個數據,sql語句直接就出來了。
Ⅱ sqlserver多表聯合查詢
selectc.discount
froma,b,cwherea.hw_name=b.hw_name
andb.sort_id=c.sort_id
anda.hw_name='蘋果'
Ⅲ sqlserver多表查詢語句
select a.*,b.remark,c.content from a,b,c where patindex('%'+convert(varchar,b.id)+'%',a.fb)>0
or patindex('%'+convert(varchar,c.id)+'%',a.fb)>0
Ⅳ sqlserver多表查詢
既然三個表都是有關聯的,先單表統計
,再合起來統計。。
select
A.*,BC.sum_B,BC.sum_C
from
A表
as
A
join
(
select
單位編碼,sum_B,sum_C
from
(select
單位編碼,sum(數據B)
as
sum_B
from
B表
group
by
單位編碼)
as
B
join
(select
單位編碼,sum(數據C)
as
sum_C
from
C表
group
by
單位編碼)
as
C
on
B.單位編碼=C.單位編碼
)
as
BC
on
A.單位編碼=BC.單位編碼
簡化下:
select
A.*,B.sum_B,C.sum_C
from
A表
as
A
join
(select
單位編碼,sum(數據B)
as
sum_B
from
B表
group
by
單位編碼)
as
B
on
A.單位編碼=B.單位編碼
join
(select
單位編碼,sum(數據C)
as
sum_C
from
C表
group
by
單位編碼)
as
C
on
A.單位編碼=C.單位編碼
Ⅳ sqlserver多表聯合查詢
select a.a_name as 名字,count(b.a_id) as 數量 from a inner join b on a.a_id = b.a_id group by a.a_name
名字 數量
me 3
wo 1
he 1
select a.a_name as 名字,count(b.a_id) as 數量 from a left join b on a.a_id = b.a_id group by a.a_name
名字 數量
me 3
wo 1
he 1
she 0
our 0