當前位置:首頁 » 編程語言 » sqlserver多表查詢

sqlserver多表查詢

發布時間: 2022-12-23 16:53:44

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

熱點內容
手機網頁連接不上伺服器如何解決 發布:2025-07-04 03:29:57 瀏覽:921
計算機多級存儲系統 發布:2025-07-04 03:24:22 瀏覽:283
流控搭腳本 發布:2025-07-04 03:05:59 瀏覽:110
編程的引號 發布:2025-07-04 03:01:09 瀏覽:786
百度雲不能上傳文件 發布:2025-07-04 02:59:28 瀏覽:664
皇冠哪個配置上駕駛座前後移動 發布:2025-07-04 02:45:56 瀏覽:92
安卓沒銀行卡怎麼充值 發布:2025-07-04 02:40:13 瀏覽:668
家教網php源碼 發布:2025-07-04 02:40:11 瀏覽:51
外錐度編程 發布:2025-07-04 02:37:28 瀏覽:969
炫舞二級密碼怎麼設置 發布:2025-07-04 02:31:50 瀏覽:976