Skip to content
Advertisement

Why is my group by not grouping my values as expected?

My project is a clothes factory and I have 3 tables.

  1. Person : A table that contains people’s name
  2. Category : Contains each category of clothes in the factory (sockets, shoes, etc.)
  3. Quantity : The quantity of clothes for each person

And I’m trying to display something like this :

Name Quantity_shoes Quantity_shirts Quantity_sockets Quantity_hats
Paul 8 25 38 0

But my result isn’t that I expected… I got this :

Name Quantity_shoes Quantity_shirts Quantity_sockets Quantity_hats
Paul 8 0 0 0
Paul 0 0 0 0
Paul 0 25 0 0
Paul 0 0 38 0

It seems that I have one row for each category. So I tried to groupbyquantity but it doesn’t sum my quantity and I have more rows.

What I am doing wrong?

Advertisement

Answer

As suggested in the above try this (I am guessing the column in person with the name is p.name in which case you may not even need the group by name):

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