| Column id | status |
| 1 | Accept |
| 1 | Shipped |
| 1 | Received |
| 2 | Accept |
| 2 | Received |
| 3 | Accept |
| 3 | Shipped |
| 3 | Received |
我希望输出中的那些ID尚未发送但已经收到的ID。 (未发货但收货)(id 2)
答案 0 :(得分:0)
希望这会有所帮助:
select column_id
from table
where status = 'Received'
minus
select column_id
from table
where status = 'Shipped'
答案 1 :(得分:0)
这是获取id
和相应的status
select *
from
(select id ,listagg(status,',') within group(order by id) status_concat
from table
group by id) CTE
where CTE.status_concat='Accept,Received';
如果不需要硬编码并且状态仅为这3个('Accept','Received','Shipped')
,则下面的查询也将起作用
select id
from
(select count(*) CNT,id from table
group by id) CTE
where CTE.CNT=2;