Skip to content
Advertisement

SQL Server : search among groups based on multiple conditions

I have the following Product table. I’m trying to find the products based on multiple criteria.

Here’s my sample data:

There are a total of three products.

I want to search the products with lowest new price, lowest used price, and premium price among premium service offered products.

My expected result is:

I’ve tried to write a query with group by and having clause but my results didn’t make any sense! Even I’m not sure which functions/clause I need to use!

Need your help…

Advertisement

Answer

Hmmm . . . if I understand correctly, this is conditional aggregation with a having clause:

If premium_service is a bit, you can convert to an integer:

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