当前位置:首页 » 编程语言 » 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 17:25:02 浏览:822
c语言for中continue 发布:2025-05-16 17:20:14 浏览:647
ftp储存 发布:2025-05-16 17:04:08 浏览:504
家悦3010怎么看电脑配置 发布:2025-05-16 17:02:38 浏览:885
sqlin传参 发布:2025-05-16 17:02:37 浏览:889
python计算md5 发布:2025-05-16 17:02:32 浏览:427
看算法头疼 发布:2025-05-16 16:56:41 浏览:798
给定文件编译成dll文件 发布:2025-05-16 16:45:05 浏览:730
熔喷机的配置有哪些 发布:2025-05-16 16:45:04 浏览:720
20149月二级c语言 发布:2025-05-16 16:22:29 浏览:961