0

Let's say I have a table name receipts. Then the table has a receipt_num, product, and price.

Let's say I have a table that looks like this.

receipt_num | item | price
    --------+------+------
    6       | a    | 10
    6       | b    | 15
    1       | c    | 7

What SQL query can I use to get something like this.

receipt_num | price
    --------+------+------
    6       | 25
    1       | 7

Essentially I am combining all the rows with the same receipt_num, excluding the item column and adding up the total price.

I have tried using SELECT receipt_num, price FROM receipts. I am very new at this so I am not sure what I am doing wrong.

1 Answer 1

2

This is an aggregation query -- a very basic SQL operation:

select receipt_num, sum(price)
from receipts
group by receipt_num;

I strongly encourage you to find tutorials, books, lessons or something so you can learn the fundamental ideas in SQL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.