user3141181
user3141181

Reputation: 99

Query for total earnings

I have the following table 'collection'. It stores the sales from 2 shops in the form of cash and card:

Date        |  Shop | Cash | Card |
-----------------------------------
2017-01-01  |   A   |  10  |  5   |
2017-01-01  |   B   |   8  |  2   |
2017-01-02  |   A   |   9  |  6   |
2017-01-02  |   B   |   8  |  5   |
2017-01-03  |   A   |   9  |  7   |
2017-01-03  |   B   |  10  |  1   |

I want to run the SQL query and get the total daily earning from the two shops as the following output

Day    |   Earnings
-------------------
1      |   25
2      |   28
3      |   27

Upvotes: 1

Views: 306

Answers (2)

Yogesh Sharma
Yogesh Sharma

Reputation: 50163

Just Check as below :

SELECT row_number() over (order by date) AS Day
         ,SUM(Cash + Card) AS Earnings
     FROM #TEMP
 GROUP BY Date

Upvotes: 0

Esteban P.
Esteban P.

Reputation: 2809

Should be easy with a simple GROUP BY like:

   SELECT Date
         ,SUM(Cash + Card) AS Earnings
     FROM yourtable
 GROUP BY Date

Upvotes: 2

Related Questions