I need to group rows by account.
If there's only one row in a group, select it.
If there are multiple rows per group, select columns of the row with order_number equal to 4 but set order_number to 1.
myTable data:
account order_number status state
1111 4 ok full
2256 4 ok full
3344 1 NULL NULL
1111 1 NULL NULL
8743 4 ok full
2256 1 NULL NULL
Here's what I've tried:
select
account,
order_number,
status,
state,
case
when order_number = '1' then 'pass'
when order_number = '4' then 'fail'
end as ' TEST RESULTS '
from myTable
This is the result I'm trying to achieve:
account order_number status state
1111 1 ok full
2256 1 ok full
3344 1 NULL NULL
8743 4 ok full