SQL Query

I have a table like this. 2 types of orders Credit and Cancel. There are not in order.

Order Type Date
CS123 Credit 2018-03-01
CS123 Cancel 2018-03-02
CS200 credit 2018-03-02
CS300 credit 2018-03-02
CS300 cancel 2018-03-03
CS300 credit 2018-03-03

I need to get output of Orders .

CS200
CS300 ( becuase 1 cancels out , but 1 remaining )

Note CS123 doesnt show up as it cancels out

Something like

select order
  from yourtable
 group by order
 having sum(case when type='Cancel' then -1 else 1 end)>0
;
1 Like