當前位置:首頁 » 編程語言 » 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-05-16 20:55:13 瀏覽:905
linuxmysql慢日誌 發布:2025-05-16 20:47:58 瀏覽:270
村兩委有哪些配置 發布:2025-05-16 20:34:47 瀏覽:292
我的世界有什麼伺服器好玩的 發布:2025-05-16 20:28:57 瀏覽:482
c語言按位與運算 發布:2025-05-16 20:24:10 瀏覽:753
蘋果手機如何修改密碼安全 發布:2025-05-16 20:23:34 瀏覽:193
圖片文字識別演算法 發布:2025-05-16 20:21:54 瀏覽:45
校園ftp伺服器 發布:2025-05-16 20:19:38 瀏覽:71
數據加密技術的實現 發布:2025-05-16 20:12:49 瀏覽:158
華為p9擴存儲 發布:2025-05-16 20:03:22 瀏覽:414