Skip to content
Advertisement

How to use DISTINCT and SUM in a same SQL query on MS SQL Express

enter image description hereI have a situation where I need to get DISTINCT values from column “note” and then get the SUM of “price” for above records.

I tried with different queries but none of them are working fine.

In a nutshell I need to get the sum of prices for the distinct records.

Advertisement

Answer

Maxbe this will be one way to do it:

Here is a demo on SQLServer

If I have understood you correctly you need distinct note values and only one sum for all of them … then something like this:

P.S. do add expected result….

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