为了使比较案例不敏感但显示正确,我们在下面写了查询
WITH VALUE_LIST
AS (SELECT *
FROM (SELECT m1."ASSIGNMENT" col#0,
m1."ASSIGNEE_NAME" col#1,
ROW_NUMBER ()
OVER (
PARTITION BY m1."ASSIGNMENT", m1."ASSIGNEE_NAME"
ORDER BY m1."ASSIGNMENT", m1."ASSIGNEE_NAME")
ROW_INDEX
FROM PROBSUMMARYM1 m1)
WHERE ROW_INDEX = 1)
SELECT vl.col#0, vl.col#1, GROUPED_DATA.CNT
FROM ( SELECT UPPER (m1."ASSIGNMENT") col#0,
UPPER (m1."ASSIGNEE_NAME") col#1,
COUNT (*) CNT
FROM PROBSUMMARYM1 m1
GROUP BY UPPER (m1."ASSIGNMENT"), UPPER (m1."ASSIGNEE_NAME")
ORDER BY UPPER (m1."ASSIGNMENT") ASC, UPPER (m1."ASSIGNEE_NAME") ASC)
GROUPED_DATA,
VALUE_LIST vl
WHERE ( GROUPED_DATA.col#0 = UPPER (vl.col#0)
OR (GROUPED_DATA.col#0 IS NULL AND vl.col#0 IS NULL))
AND ( GROUPED_DATA.col#1 = UPPER (vl.col#1)
OR (GROUPED_DATA.col#1 IS NULL AND vl.col#1 IS NULL))
但随着群体数量的增加,性能会显着下降。 是否有任何查询可以获得相同的查询但没有性能问题?
答案 0 :(得分:1)
尝试此查询:
SELECT ASSIGNMENT,
ASSIGNEE_NAME,
CNT
FROM (
SELECT m1."ASSIGNMENT",
m1."ASSIGNEE_NAME",
row_number() OVER (
PARTITION BY m1."ASSIGNMENT", m1."ASSIGNEE_NAME"
ORDER BY m1."ASSIGNMENT", m1."ASSIGNEE_NAME"
) As ROW_INDEX,
COUNT(*) OVER (
PARTITION BY UPPER (m1."ASSIGNMENT"),
UPPER (m1."ASSIGNEE_NAME")
) As CNT
FROM PROBSUMMARYM1 m1
)
WHERE ROW_INDEX = 1
;
作为旁注,这部分查询在quuestion中:
WITH VALUE_LIST
AS (SELECT *
FROM (SELECT m1."ASSIGNMENT" col#0,
m1."ASSIGNEE_NAME" col#1,
ROW_NUMBER ()
OVER (
PARTITION BY m1."ASSIGNMENT", m1."ASSIGNEE_NAME"
ORDER BY m1."ASSIGNMENT", m1."ASSIGNEE_NAME")
ROW_INDEX
FROM PROBSUMMARYM1 m1)
WHERE ROW_INDEX = 1)
是这个版本的一个非常复杂的版本:
SELECT DISTINCT m1."ASSIGNMENT" col#0,
m1."ASSIGNEE_NAME" col#1
FROM PROBSUMMARYM1 m1