I need to make two columns from single column price depending upon if it is used/secondhand or new. Old is indicated by used somewhere in format column. One being ‘price ex tax’ other is the price with tax. I hope the following code (with no error but malfunction in accordance to my requirement) explains it better.
case when format =’%used%’ or format=’%secondhand%’ then CAST(price AS
UNSIGNED INTEGER) else CAST(price AS UNSIGNED INTEGER)*0.8 end as
‘Pris ex Tax’,
CAST(price AS UNSIGNED INTEGER) as Price
Here basically I need to show a column with price*0.8 for new products and just price for used products.
format in the data base contains information for used articles as used/secondhand but nothing for new.
I followed this link
as well as some of the related questions in stackoverflow
but not enough for me to understand.
I tried to put the output here but found it difficult to do that. I will do it if you think will be require to solve it.
This is a great link that teaches Inline IF and CASE statement in MySQL.
code snippet:
IF StatementCASE Statement