I have the following problem when sorting some records:
As you can see in the image, I am trying to filter some sales and I get duplicate fields: for example the tapas...
It should be sorted by NomFam "Family name".
Changing the order of the GROUP BY:
The thing is that if I don't put those GROUP BY I get a grouping error...
Greetings and thank you very much!
The problem is that you are grouping
ImporteBruto
, and that you are confused with how to get the percentage. If I understand correctly, the percentage is based on the total gross amount of your filtered data, which is a different figure from the one you are calculating.A quick way to get what you're looking for would be to use the following query (assuming SQL Server 2005+):
Ordering and grouping are independent... You have to add a clause
order by
to order the way you want:I think you ask for this:
Add order by NomFam and if you want to order it by other fields add order by NomFam,CodFam,ImporteBruto