I am looking to output the substring where country = 'us' only and leave the substring blank for all other countries. I have tried the below commented-out part but I am not sure my structure/logic is correct. Any help would be great
SELECT DISTINCT country, ID, Name --, IF(country ='US', "SUBSTRING(ID, 3, 5)", " " ) AS substring
FROM TestTable
1条答案
按热度按时间2fjabf4q1#
As @Squirrel mentioned in the comments you can use
CASE
to fix your issue, the code then would look like this: