I have a column in DB table named type. It have values like 01,78,75,98,02,11 etc. I want to map these values into a string value like, If the value starts with 01 map it into a string value named type01, and if starts with 78 the value (select result value) must be type7 etc. Any idea guys how to do it? Thanks in advance.
SQL will be somehow like below:
Select (if(type left(2) = 07 then type7), t.dept
from team t
LEFT JOIN typetable
ON typetable.id=t.team_id;
It seems you may want a case statement if I understand correctly what you are asking.
SELECT CASE type
WHEN '01' THEN 'type01'
WHEN '02' THEN 'type02'
WHEN '03' THEN 'type03'
WHEN '04' THEN 'type04'
END
FROM team
LEFT JOIN typetable
ON typetable.id=t.team_id;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With