Reputation: 35
Actually am trying to create a temporary column in the output:
E.g.:
Name sold_cost
jjj 900
hhh -600
Desired output:
name in_profit in_loss
jjj 900 -
hhh - -600
Upvotes: 1
Views: 28
Reputation: 311143
You could use a case
expression with separate expressions for in_profit
and in_loss
:
SELECT name,
CASE WHEN sold_cost > 0 THEN sold_cost ELSE '-' END AS in_profit,
CASE WHEN sold_cost < 0 THEN sold_cost ELSE '-' END AS in_loss
FROM my_table
Upvotes: 2