我有以下SQL查询:
SELECT
(SELECT CATEGORY_NAME FROM tableA WHERE NUM_CRITERIA != 0) AS "Name",
(numYes / (criteriaCount * numParts - numNA)) / numParts AS "Progress"
FROM (
SELECT
(SELECT NUM_CRITERIA FROM tableA WHERE NUM_CRITERIA != 0) AS criteriaCount,
(SELECT COUNT(*) FROM tableB WHERE RESPONSE = 'Yes' AND ASSEMBLY_ID = 1) AS numYes,
(SELECT COUNT(*) FROM tableB WHERE RESPONSE = 'N/A' AND ASSEMBLY_ID = 1) AS numNA,
(SELECT COUNT(*) FROM tableC WHERE ASSEMBLY_ID = 1) AS numParts
FROM DUAL
)
此查询的目标是从各个表中选择列,并使用这些列的值来计算“Progress”列的值。我需要“Progress”列来在代码中计算criteriaCount列的每个值。这段代码在oracle apex中编译得很好,但是当它运行时,我得到了一个ORA-01427错误,因为criteriaCount查询返回了多行。
任何帮助将不胜感激
1条答案
按热度按时间ktca8awb1#
由于
TableA
的查询可以返回多行(这是您想要的),因此不能将其与其他查询一起放置为 * 标量子查询 *。您需要直接查询
TableA
并将结果与其他子查询连接。例如: