我想在PL / SQL Developer的Oracle DataBAse中对来自不同表的值进行求和,所以我准备了这个SQL语句:
select sum(total) as ttt from
(select count('1') as total
from vehicle_hotel
union
select count('1') as total
from alarm
union
select count('1') as total
from vd_poi
union
select count('1') as total
from person_hotel
union
select count('1') as total
from social_office_transaction
union
select count('1') as total
from person_hotel_field_value
union
select count('1') as total
from pd_trf_week
union
select count('1') as total
from aggreg_exception
union
select count('1') as total
from pd_week_rec;
select count('1') as total
from hist_pd_week_rec
union
select count('1') as total
from pd_week);
但我收到了这个错误:
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
Error en la línea: 32, columna: 12
答案 0 :(得分:2)
您的查询有一些问题,我修复了这些问题,下面列出了从坏到坏的降序:
from pd_week_rec;
中有一个迷路分号......这可能是你看到的特定错误的原因UNION
,如果两个子查询碰巧巧合的计数相同,则可能导致错误的结果COUNT('1')
,也许并没有错,但我会使用COUNT(*)
代替
select sum(total) as ttt
from
(
select count(*) as total
from vehicle_hotel
union all
select count(*)
from alarm
union all
select count(*)
from vd_poi
union all
select count(*)
from person_hotel
union all
select count(*)
from social_office_transaction
union all
select count(*)
from person_hotel_field_value
union all
select count(*)
from pd_trf_week
union all
select count(*)
from aggreg_exception
union all
select count(*)
from pd_week_rec
select count(*)
from hist_pd_week_rec
union all
select count(*)
from pd_week
) t;