I have a query result that outputs customerID
and transaction descrip.
From the same query, I actually want to only extract the transaction descript = 'refund'
from all the customers. Some customers do not have the 'refund' value and if so, return as null value
ex)
This is the result I get from the query:
CustomerID A | Descrip. B |
---|---|
1 | purchase |
1 | refund |
2 | refund |
3 | purchase |
4 | purchase |
But it should be like this:
CustomerID A | Descrip. B |
---|---|
1 | refund |
2 | refund |
3 | null |
4 | null |
CodePudding user response:
select CustomerID,
max(case when Descrip = 'refund' then Descrip else null end) as Description
from your_table_query
group by CustomerID