Skip to content
Advertisement

need an additional column in SQL output

I have a table called product_info where there are two columns(product, product_id).There are 5 ‘product_id’ and 10 ‘product’. I wrote the following code to list products and their count.Now I need to create an additional column called ‘favorite_product’ if the ‘product’ count is more than 3.When I tried with a couple of WHERE clause options, it filtered out my existing column (product_count) which I need to keep intact in the output. How can I do that? Any help would be appreciated.

Advertisement

Answer

Just use a case expression:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement