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 by  john rob
 1151  View(s)
Ratings:
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?

  1. Anchal Kesharwani

    Post:10

    Points:70
    Re: Is it possible to calculate the sum of each group in a table without using group by clause in SQL Server?

    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;



      Modified On Apr-05-2018 05:58:03 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!