Apex不喜欢我的COUNT / GROUP BY sql

时间:2016-03-07 13:15:40

标签: sql oracle oracle-apex

我正在尝试在apex 4.0的交互式报表中执行此查询,并且我不断收到以下错误:

The report query needs a unique key to identify each row. The supplied key cannot be used for this query. Please edit the report attributes to define a unique key column. ORA-01446: cannot select ROWID from, or sample, a view with DISTINCT, GROUP BY, etc.

如果我删除该组,则会抛出一个错误,询问group by,这是SQL:

SELECT
D.DTITLE,
COUNT(DCOPY.DID) as Stock
FROM RENT
LEFT JOIN D ON RENT.DID = D.DID
LEFT JOIN DCOPY ON RENT.DID = DCOPY.DID
WHERE RENT.ID IS NULL
GROUP BY D.DTITLE

表D:

Column Name Data Type   Nullable    Default Primary Key
DID VARCHAR2(10)    No  -   1
RATEID  VARCHAR2(10)    No  -   -
DESC    VARCHAR2(40)    No  -   -
DTITLE  VARCHAR2(40)    No  -   -

表租:

Column Name Data Type   Nullable    Default Primary Key
RENTID  VARCHAR2(10)    No  -   1
DUSERID VARCHAR2(10)    No  -   -
PRIORITYID  VARCHAR2(10)    No  -   -
DID VARCHAR2(10)    Yes -   -
DISPLAYID   VARCHAR2(10)    Yes -   -
DISPLAYDATE DATE    Yes -   -
DCOPYID VARCHAR2(10)    Yes -   -

2 个答案:

答案 0 :(得分:1)

您的查询没问题,您需要指定一个唯一列,该列可用作每行上的链接以查看相应的行详细信息或删除链接选项。默认情况下,报告假定您希望每行上都有链接以查看相应的行详细信息(单个记录视图)。

答案 1 :(得分:0)

您的查询在语法上不正确(表别名不正确)。也许如果查询是固定的,那么代码将起作用:

SELECT D.DTITLE, COUNT(dc.DID) as Stock
FROM RENT r LEFT JOIN
     DVD d
     ON r.DID = D.DID LEFT JOIN
     DVDCOPY dc
     ON r.DVDID = dc.DID
WHERE r.ID IS NULL
GROUP BY D.DTITLE;