例子如下:A B 表结构一样 ,实际不止两张表,也许5张10张这样的。
1.
select (
(select count(1) from A as a where a.xxx=xxx left join C as c on a.xxx=c.xxx)+(select count(1) from A as b where b.xxx=aa left join C as c on b.xxx=c.xxx)
)as total
发现这样表多了,很耗时。
2.
select count(1)
from
(
select xxx from A as a where a.xxx=xxxx
union all
select xxx from B as b where b.xxx=xxxx
)as t
left join C as c on t.xxx=c.xxx
where
c.id=xxx
求高手,求dba.
相关问题
- SQLSERVER偶发性错误:用户 'sa' 登录失败。 原因: 无法打开明确指
- Microsoft SQL Server Management Studio 图标不显示。
- sql 分组筛选问题
- MSSQL 的 Stored Procedure 显示 The text is encrypted
- 怎么使用 计算机名称 来访问某一域名下的SQL数据库
select sum(qty) from (select count(1) as qty from a union all select count(1) as qty from b)