getting the sum of values in sql

Mr. T 0 Reputation points

Hi. I have a table output in SQL

Apples 10

Oranges 20

Pears 50

How do I show the sum of thewse values under the values column?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,113 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LiHongMSFT-4306 24,926 Reputation points

    Hi @Mr. T

    Please try this query:

    Declare @temp table(fruit varchar(20), amount int)
    insert into @temp values
    SELECT fruit,SUM(amount) AS Amount
    FROM @temp


    User's image

    Best regards,

    Cosmog Hong

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments