当前位置:首页 » 编程语言 » 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

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:577
制作脚本网站 发布:2025-10-20 08:17:34 浏览:868
python中的init方法 发布:2025-10-20 08:17:33 浏览:566
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:748
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:668
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:989
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:239
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:97
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:790
python股票数据获取 发布:2025-10-20 07:39:44 浏览:696