当前位置: 代码迷 >> Sql Server >> 一个集总查询,该如何解决
  详细解决方案

一个集总查询,该如何解决

热度:118   发布时间:2016-04-27 19:31:11.0
一个集总查询
select count(*.Microsoft资料) + count(*.RAZER资料)+count(*.罗技资料) 产品总数
from Microsoft资料,RAZER资料,罗技资料

不知道是不是全域名错误。它提示是.附近错误

------解决方案--------------------
Try
SQL code
---1、Declare @M int,@R int,@RJ intSelect @M=Count(1) From Microsoft资料Select @R=Count(1) From RAZER资料Select @RJ=Count(1) From 罗技资料Select @[email protected][email protected] As 产品总数---2、Select Count(1) As 产品总数From (       Select Microsoft资料表字段1 From Microsoft资料       Union All      Select RAZER资料字段1 From RAZER资料       Union All      Select 罗技资料字段1 From 罗技资料 ) As T
------解决方案--------------------
不应该用连接
应该每个表分别统计后再相加 

select (select count(*) from Microsoft资料)+(select count(*) from RAZER资料)+(select count(*) from 罗技资料) as 总数
  相关解决方案