About
Pricing
Community
Teams
Start Free Trial
Log in
Jagdish Devaku
asked on
7/11/2012
Select Rows including their SUM in the last
Hi,
I have requirement as below:
My table:
Name Amount
Raj 100
Manj 200
Jag 300
John 400
Required Result:
Name Amount
Raj 100
Manj 200
Jag 300
John 400
Total 1000
I tried using UNION and it working.
But I want to write this in one query. or any other better way without using UNION or temp tables.
Thanks in advance.
Microsoft SQL Server
Microsoft SQL Server 2008
Microsoft SQL Server 2005
10
4
Last Comment
Jagdish Devaku
8/22/2022 - Mon
Habib Pourfard
7/11/2012
As far as I know, it is not possible except for UNION, temp tables or table variable...
SOLUTION
Jim Horn
7/11/2012
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.
deighton
7/11/2012
this may meet your needs, there are drawbacks such as you have to avoid a name being NULL
SELECT COALESCE(dq.name, 'TOTAL'), dq.total FROM (select name, sum(amount) AS total from YourTable
group by name with rollup) AS DQ
Aaron Tomosky
7/11/2012
Also, without an order by you never know how the rows will line up. If this matters...
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
SOLUTION
deighton
7/11/2012
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Habib Pourfard
7/11/2012
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Jim Horn
7/11/2012
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Anthony Perkins
7/11/2012
I tried using UNION and it working.
But I want to write this in one query.
Just a minor quible: A SELECT statement with a UNION clause is still one query.
Jagdish Devaku
7/12/2012
ASKER
Thanks all for the help.
I am checking the queries.
Jagdish Devaku
8/30/2012
ASKER
Thanks for all your support.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.