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

热点内容
华硕天选2air配置如何选择 发布:2025-07-03 16:10:09 浏览:570
asp搜索源码 发布:2025-07-03 15:49:55 浏览:234
医美大数据库 发布:2025-07-03 15:47:07 浏览:356
c语言将二进制转化为十进制 发布:2025-07-03 15:32:47 浏览:987
c语言帮助文档 发布:2025-07-03 15:22:43 浏览:319
双端口存储器在情况下会发生读写冲突 发布:2025-07-03 15:12:54 浏览:270
快站数据库 发布:2025-07-03 14:45:44 浏览:40
jsp获取上传文件路径 发布:2025-07-03 14:44:46 浏览:569
php时间微妙 发布:2025-07-03 14:39:38 浏览:844
巨豆豆手机回复出厂密码是什么 发布:2025-07-03 14:35:19 浏览:474