我需要帮助让这段代码正常工作。我正在尝试使用两个sql语句来执行除法。
select ((select count(p.issued)
from permit p
where trunc(p.issued) >= trunc(TO_DATE('1/1/2011','MM/DD/YYYY'))
AND trunc(p.issued) <= trunc(TO_DATE('1/31/2011','MM/DD/YYYY')))
/
(select count(p.issued)
from permit p
where (TO_DATE(p.issued) - sysdate) <= 21
and trunc(p.issued) >= trunc(TO_DATE('1/1/2011','MM/DD/YYYY'))
AND trunc(p.issued) <= trunc(TO_DATE('1/31/2011','MM/DD/YYYY')))) as permitPercemt;
答案 0 :(得分:3)
您需要再添加一个SELECT
:
SELECT ( (select ....)/(select ... )) as permitPercent FROM DUAL;
<强>更新强> 所以你的查询看起来像:
SELECT (
(
select count(p.issued)
from permit p
where trunc(p.issued) >= trunc(TO_DATE('1/1/2011','MM/DD/YYYY'))
AND trunc(p.issued) <= trunc(TO_DATE('1/31/2011','MM/DD/YYYY'))
) /
(
select count(p.issued)
from permit p
where (TO_DATE(p.issued) - sysdate) <= 21
and trunc(p.issued) >= trunc(TO_DATE('1/1/2011','MM/DD/YYYY'))
AND trunc(p.issued) <= trunc(TO_DATE('1/31/2011','MM/DD/YYYY'))
)
) as permitPercent FROM DUAL;
答案 1 :(得分:1)
你没有划分整个选择陈述。
您将两个值分开并将其作为选择列表中的列返回。