How to sum row total???

00529562 40 Reputation points
2023-04-06T02:58:29.0566667+00:00

Hi. I know how to sum column total. Just add up each column. But I don't know how to calculate the total of rows, can someone guide me? Thanks.

SQL Server | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. Anonymous
    2023-04-06T03:02:47.3266667+00:00

    Hi @00529562
    You can take a look at this simple example.

    create table test(id int,col1 int,col2 int,col3 int);
    insert into test values
    (1,1,1,1),(2,2,5,3),(3,1,6,7);
    
    select id,sum(col1) as col1,sum(col2) as col2,sum(col3) as col3 
    from test group by grouping sets(id,());
    

    Output: User's image

    If you still have questions, you need to provide a datasheet so that we can help you further. User's image

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.