简体   繁体   中英

SQL query to join rows with same values

I've come across a problem that I don't really know how to solve. I have a table which looks somewhat like this:

ID   Name     Price     Quantity
1    BookA      5         10
2    BookB     10         15
3    BookA     15         15
4    BookA      5         25

How could I join rows which have same Name, same Price and sum Quantity? So it would look like this:

ID   Name     Price     Quantity
1    BookA      5         35
2    BookB     10         15
3    BookA     15         15

Thank you in advance!

This is just a simple GROUP BY query:

SELECT Min(ID), Name, Price, Sum(Quantity) as Quantity
FROM yourtable
GROUP BY Name, Price;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM