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
Microsoft SQL Server

Avatar of undefined
Last Comment
staleb

8/22/2022 - Mon
Barry Cunney

Hi Staleb,
Please try the following:

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

Open in new window

staleb

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

ASKER
think I may have solved it with stuff  function
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Sharath S

What is your SQL Server version?
staleb

ASKER
SQL 2012
ASKER CERTIFIED SOLUTION
Sharath S

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
staleb

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

Tnx
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.