有2张表,结构一样
select sum(count(*)) from (select count(*) from details20091201 union all select count(*) from details20091202)
想把2个表算出来的结果求和,但是一直报错应该怎么改?
select sum(count(*)) from (select count(*) from details20091201 union all select count(*) from details20091202)
想把2个表算出来的结果求和,但是一直报错应该怎么改?
(select count(*) from details20091201)
+(select count(*) from details20091202)
(
select count(*) cnt from details20091201
union all
select count(*) cnt from details20091202
) t
try it
(
select 1 cnt from details20091201
union all
select 1 cnt from details20091202
) t
from(
select * from details20091201
union all
select * from details20091202
)a
select count(*) cc from details20091201 union all
select count(*) from details20091202)
select count(*) cc from details20091201 union all
select count(*) from details20091202)
or
select count(*)
from(
select * from details20091201
union all
select * from details20091202
)a
select
(select count(*) from details20091201)
+(select count(*) from details20091202)里面"+"是不是相当于union?
如果我需要对两个字段求和还可以用这种形式吗?
比如
select sum(cnt),sum(cnt1) from
(
select count(*) cnt ,sum(ye) cnt1 from details20091201
union all
select count(*) cnt,sum(ye) cnt1 from details20091202
) t
还可以改成2L那种形式吗?
select
(select count(*) from details20091201)
+(select count(*) from details20091202)里面"+"是不是相当于union?
--不是加在那里是算术计算,而UNION 是结果集的合并。
(
select count(*) cnt ,sum(ye) cnt1 from details20091201
union all
select count(*) cnt,sum(ye) cnt1 from details20091202
) t
还可以改成2L那种形式吗?--这样是可以的。
说实话,根本没看懂你这个需求的意思.最好给出完整的表结构,测试数据,计算方法和正确结果.发帖注意事项
http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
select
(select count(*) from details20091201)
+(select count(*) from details20091202) cnt,
(select sum(ye) from details20091201)
+(select sum(ye) from details20091202) amt