Skip to content
Advertisement

SQL select row with max value or distinct value and sum all

I have the following data that is returned to me. I need to get a distinct or max sum of all the commission by taxid for a single repnbr. The ‘qtrlycommrep’ column is the value I’m trying to get to, but not able to. For repnbr c590, I need to get the 854.66 commission amount, which is the max for each taxid.

What am I doing wrong?

Any help would be much appreciated!

enter image description here

Here’s what I’ve tried so far. Using the Row_number

Cross Apply

inner join

order by row_number

Advertisement

Answer

You want one value per tax id. You need to include that. For instance:

However, I would be inclined to use two levels of aggregation:

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