added query draft
This commit is contained in:
parent
8543aab366
commit
5ae0a5856e
39
query_draft.sql
Normal file
39
query_draft.sql
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
SELECT
|
||||||
|
cluster,
|
||||||
|
id,
|
||||||
|
worker,
|
||||||
|
evidence_type,
|
||||||
|
evidence,
|
||||||
|
category,
|
||||||
|
polarity,
|
||||||
|
created_at,
|
||||||
|
created_by
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
cluster,
|
||||||
|
id,
|
||||||
|
worker,
|
||||||
|
evidence_type,
|
||||||
|
evidence,
|
||||||
|
category,
|
||||||
|
polarity,
|
||||||
|
created_at,
|
||||||
|
created_by,
|
||||||
|
ROW_NUMBER() OVER (PARTITION BY category ORDER BY created_at DESC) AS rn
|
||||||
|
FROM (
|
||||||
|
(
|
||||||
|
SELECT "user" as cluster, id, product_id, null as worker, evidence_type, evidence, unnest(claim) as category, true as polarity, created_at, created_by FROM user_claims
|
||||||
|
UNION ALL
|
||||||
|
SELECT "automated" as cluster, id, product_id, worker, null as evidence_type, evidence, unnest(claim) as category, true as polarity, created_at, null as created_by FROM automated_claims
|
||||||
|
)
|
||||||
|
UNION ALL
|
||||||
|
(
|
||||||
|
SELECT "user" as cluster, id, product_id, null as worker, evidence_type, evidence, unnest(counter_claim) as category, false as polarity, created_at, created_by FROM user_claims
|
||||||
|
UNION ALL
|
||||||
|
SELECT "automated" as cluster, id, product_id, worker, null as evidence_type, evidence, unnest(counter_claim) as category, false as polarity, created_at, null as created_by FROM automated_claims
|
||||||
|
)
|
||||||
|
)
|
||||||
|
WHERE product_id = ???
|
||||||
|
)
|
||||||
|
WHERE rn = 1
|
||||||
|
ORDER BY created_at;
|
Loading…
Reference in a new issue