एक सीटीई का प्रयोग करें जो उन सभी पंक्तियों को लौटाता है जहां A = C
और तालिका में शामिल हों:
with cte as (
select * from tablename
where "A" = "C"
)
select distinct t."A", t."B", c."D"
from tablename t left join cte c
on c."A" = t."A" and c."B" = t."B"
order by t."A", t."B"
डेमो
देखें .
परिणाम:
| A | B | D |
| --- | --- | --- |
| x | 0 | 1 |
| x | 1 | |
| y | 0 | |
| y | 1 | 0 |