當前位置:首頁 » 編程語言 » 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-09-18 10:21:52 瀏覽:182
linux怎麼編譯c文件 發布:2025-09-18 09:55:16 瀏覽:302
python安裝後無法運行 發布:2025-09-18 09:45:57 瀏覽:236
安卓手機怎麼剪輯音樂 發布:2025-09-18 09:44:16 瀏覽:781
伺服器地址修改在哪找 發布:2025-09-18 09:42:41 瀏覽:441
sntp伺服器地址 發布:2025-09-18 09:28:36 瀏覽:552
phpunit 發布:2025-09-18 09:25:19 瀏覽:571
怎麼改伺服器的ip地址嗎 發布:2025-09-18 09:24:33 瀏覽:12
編譯703n固件 發布:2025-09-18 08:50:59 瀏覽:541
三星手機系統文件夾是哪個文件夾 發布:2025-09-18 08:48:45 瀏覽:284