sql两张表union all的时候取 count,然后进行sum,该怎么实现?? 急急急.....
oracle是这样的:selectsum(tmpcount)from(selectcount(*)astmpcountfromtab1unionallselectcoun...
oracle 是这样的:
select sum(tmpcount) from (
select count(*) as tmpcount from tab1
union all
select count(*) as tmpcount from tab2
)
这种写法在sql底下报错,')' 附近有语法错误。请问,在sql里面如何实现同样的功能?? 展开
select sum(tmpcount) from (
select count(*) as tmpcount from tab1
union all
select count(*) as tmpcount from tab2
)
这种写法在sql底下报错,')' 附近有语法错误。请问,在sql里面如何实现同样的功能?? 展开
展开全部
在最后的地方 随便加个字符, ) a就可以了。缺少一个表名,相当于。
select sum(tmpcount) from (
select count(*) as tmpcount from tab1
union all
select count(*) as tmpcount from tab2
) a
具体如下:
1、简介
结构化查询语言(Structured Query Language)简称SQL,结构化查询语言是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统;sql 语句就是对数据库进行操作的一种语言。
2、sql语句
更新:update table1 set field1=value1 where 范围
查找:select * from table1 where field1 like '%value1%' (所有包含'value1'这个模式的字符串)
排序:select * from table1 order by field1,field2 [desc]
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1[separator]
展开全部
在最后的地方 随便加个字符, ) a就可以了。
缺少一个表名,相当于。
缺少一个表名,相当于。
追问
亲,能说详细点吗???
追答
select sum(tmpcount) from (
select count(*) as tmpcount from tab1
union all
select count(*) as tmpcount from tab2
) a
这样就可以了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这样:
select sum(tmpcount) from (
select count(*) as tmpcount from tab1
union all
select count(*) as tmpcount from tab2
) as tab;
select sum(tmpcount) from (
select count(*) as tmpcount from tab1
union all
select count(*) as tmpcount from tab2
) as tab;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select sum(tmpcount) from (
select count(*) as tmpcount from tab1
union all
select count(*) as tmpcount from tab2
) as a
sql的要重命名
select count(*) as tmpcount from tab1
union all
select count(*) as tmpcount from tab2
) as a
sql的要重命名
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询