Link to home
Start Free TrialLog in
Avatar of staleb
staleb

asked on

Showing multiple group values in one row

Hi how can I show multiple vaules in the same group row
(not sure if this is the right way to say it)

example
table( PalletNo, box weight, count)
Values
19,10,1
19,20,1
19,20,1
19,20,1

How do I querie this so that it will display
Pallet,   boxes,            sum(count)
19,        20x3  10x1,    4
Avatar of Barry Cunney
Barry Cunney
Flag of Ireland image

Hi Staleb,
Please try the following:

SELECT PalletNo, [box weight], COUNT(*)
FROM T
GROUP BY GROUPING SETS ((PalletNo), ([box weight]))

Open in new window

Avatar of staleb
staleb

ASKER

This gave me 3 rows.
Can these three lines be combined into one?
Avatar of staleb

ASKER

think I may have solved it with stuff  function
Avatar of Sharath S
What is your SQL Server version?
Avatar of staleb

ASKER

SQL 2012
ASKER CERTIFIED SOLUTION
Avatar of Sharath S
Sharath S
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of staleb

ASKER

Yes that worked perfect.
Also made it work with a stuff command

Tnx