我使用一个非常元的系统工作,该系统允许用户定义自己的形式和报告...以为共享点列表或wordpress,但更具市场针对性。
在这种特定情况下,“ Collection,Row”键集应始终具有一个单独的table_id到一个单独的folder_id,并且我们发现一种情况,其中某些无效数据通过了,我使用下面的查询来检查问题。
我很好奇是否有一种无需使用子查询即可产生结果的方法。
这只是一个教育/理论问题,但最终我可能需要实施检查约束以防止这些变体和性能发挥作用。
/* Only one Database table per collection set */
SELECT
ic.folder_id "Folder #"
, ic.table_id "Table #"
, LISTAGG(ic.column_id
, ',') WITHIN GROUP(
ORDER BY
ic.folder_id
, ic.table_id
) "Columns"
FROM
cols ic
WHERE
ic.folder_id IN (
SELECT
ic02.folder_id
FROM
(
SELECT
ic01.folder_id
, ic01.table_id
FROM
cols ic01
WHERE
v.key_set = 'Collection,Row'
GROUP BY
folder_id
, table_id
) ic02
GROUP BY
ic02.folder_id
HAVING
COUNT(0) > 1
)
GROUP BY
ic.folder_id
, ic.table_id;
<?xml version='1.0' encoding='8859_9' ?>
<RESULTS>
<ROW>
<COLUMN NAME="Folder_#">315</COLUMN>
<COLUMN NAME="Table_#">2141</COLUMN>
<COLUMN NAME="Variables">4397,4398,4399,4400,4401,4402,4403,4404,4405,4406,4407,4408,4409,4410,4411,4412</COLUMN>
</ROW>
<ROW>
<COLUMN NAME="Folder_#">315</COLUMN>
<COLUMN NAME="Table_#">9020</COLUMN>
<COLUMN NAME="Variables">10924,10926,10934,10935</COLUMN>
</ROW>
<ROW>
<COLUMN NAME="Folder_#">316</COLUMN>
<COLUMN NAME="Table_#">2142</COLUMN>
<COLUMN NAME="Variables">4413,4414,4415,4416,4417,4418,4419</COLUMN>
</ROW>
<ROW>
<COLUMN NAME="Folder_#">316</COLUMN>
<COLUMN NAME="Table_#">9021</COLUMN>
<COLUMN NAME="Variables">10943,10945,10949,10953,10954</COLUMN>
</ROW>
</RESULTS>
答案 0 :(得分:0)
我认为这会产生相同的结果-
SELECT
ic.folder_id "Folder #"
, ic.table_id "Table #"
, LISTAGG(ic.column_id
, ',') WITHIN GROUP(
ORDER BY
ic.folder_id
, ic.table_id
) "Columns"
FROM
cols ic
WHERE key_set = 'Collection,Row'
GROUP BY
ic.folder_id
, ic.table_id
HAVING
COUNT(0) > 1