select count (*) from
(select a.ACCOUNT_POID_ID0,a.STATUS as moov_profile_status,b.SUB_PLAN_ID,b.PLAN_ID,c.STATUS,c.NAME
from VMS_MOOV_PROFILE_T a,
VMS_SUB_PLAN_NO_REGEN_T b,
VMS_VOUCHER_CONF_T c,
where b.ACCOUNT_POID_ID0 = a.ACCOUNT_POID_ID0
and c.VOUCHER_ID = (select f.VOUCHER_ID from VMS_PLAN_VOUCHER_T f where f.PLAN_ID = b.PLAN_ID));
这会返回错误。我如何计算行数?
答案 0 :(得分:1)
Try this
SELECT count (*)
FROM (SELECT a.ACCOUNT_POID_ID0,
a.STATUS AS moov_profile_status,
b.SUB_PLAN_ID,
b.PLAN_ID,
c.STATUS,
c.NAME
FROM VMS_MOOV_PROFILE_T a,
VMS_SUB_PLAN_NO_REGEN_T b,
VMS_VOUCHER_CONF_T c
WHERE b.ACCOUNT_POID_ID0 = a.ACCOUNT_POID_ID0
AND c.VOUCHER_ID = (SELECT f.VOUCHER_ID
FROM VMS_PLAN_VOUCHER_T f
WHERE f.PLAN_ID = b.PLAN_ID)) t
答案 1 :(得分:0)
您的错误是:
更正的查询是:
select count (*) from
(
select a.ACCOUNT_POID_ID0,a.STATUS as moov_profile_status,b.SUB_PLAN_ID,b.PLAN_ID,c.STATUS,c.NAME
from VMS_MOOV_PROFILE_T a,
VMS_SUB_PLAN_NO_REGEN_T b,
VMS_VOUCHER_CONF_T c
where b.ACCOUNT_POID_ID0 = a.ACCOUNT_POID_ID0
and c.VOUCHER_ID = (select f.VOUCHER_ID from VMS_PLAN_VOUCHER_T f where f.PLAN_ID = b.PLAN_ID)
) dummy;
此外,您加入表的方式(使用VMS_PLAN_VOUCHER_T上的子查询)有点奇怪。而且你不应该使用二十多年前在标准SQL中替换的旧的逗号分隔连接语法。另外:无论如何,你都不需要派生表。
以下是您的简化查询:
select count (*)
from VMS_MOOV_PROFILE_T a
join VMS_SUB_PLAN_NO_REGEN_T b on b.ACCOUNT_POID_ID0 = a.ACCOUNT_POID_ID0
join VMS_PLAN_VOUCHER_T f on f.PLAN_ID = b.PLAN_ID
join VMS_VOUCHER_CONF_T c on c.VOUCHER_ID = f.VOUCHER_ID;