Home > DeveloperSection > Forums > Is it possible to calculate the sum of each group in a table without using group by clause in SQL Server?
john rob

Total Post:108

Points:756
Posted on    September-22-2014 2:46 AM

 Database Database 
Ratings:


 1 Reply(s)
 657  View(s)
Rate this:

I am trying to find out if there is any way to aggregate a sales for each Book. I realize I can achieve it either by using group-by clause or by writing a procedure. Example:

Table: Details

Sales                     Book

10                           C Language

20                           C Language

4                              C# 4.0

12                           C# 4.0

2                              C# 4.0

25                           Java

Is there a way possible to perform the following query without using group by query?

select

    Book,

    sum(Sales)

from

    Details

group by

    Book

 

I realize it is possible using Procedure, could it be done in any other way?



Anchal Kesharwani
Anchal Kesharwani

Total Post:10

Points:70
Posted on    September-22-2014 2:55 AM

hi john,

I hope that its helpful for you:

SELECT Distinct(Book),

     (SELECT SUM(Sales) FROM Details x where x.Book = a.Book) Sales

from Details a;




Don't want to miss updates? Please click the below button!

Follow MindStick