我有这张桌子TCM
:
我想从Topic_hd_id
中选择不同的TCM
,其中TCM.VALUE
来自另一个临时表T
。
例如,临时表T
的值为1000,4
:
SELECT DISTINCT(TOPIC_HD_ID)
FROM TRN.TOPICS_CATEGORY_MAPPING AS TCM
WHERE TCM.VALUE IN(1000,4)
它显示:
但是我需要申请WHERE VALUE=1000 AND VALUE=4
。
使用TPIC_HD_ID = 255
时结果只能是一行,但是使用IN
时结果将显示3行。
答案 0 :(得分:2)
使用条件聚合:
Error starting at line : 2 in command -
update invoice
set invoice_status_code = 1
where invoice_number = 2
Error report -
ORA-20005: Cannot update Orders because Shipment exists.
答案 1 :(得分:1)
额外的HAVING
子句:
SELECT TOPIC_HD_ID
FROM TRN.TOPICS_CATEGORY_MAPPING AS TCM
WHERE TCM.VALUE IN(1000,4)
GROUP BY TOPIC_HD_ID
HAVING COUNT(DISTINCT VALUE) = 2
另外,也可以使用INTERSECT
:
SELECT TOPIC_HD_ID
FROM TRN.TOPICS_CATEGORY_MAPPING AS TCM
WHERE TCM.VALUE IN(1000)
INTERSECT
SELECT TOPIC_HD_ID
FROM TRN.TOPICS_CATEGORY_MAPPING AS TCM
WHERE TCM.VALUE IN(4)