SQL Server MS SQL Aggregate View

krugob8w  于 2023-06-21  发布在  其他
关注(0)|答案(1)|浏览(109)

I have a very basic table within an MS SQL DB.
| Product | Amount | Storage Unit |
| ------------ | ------------ | ------------ |
| 1 | 34 | A |
| 1 | 10 | A |
| 2 | 20 | B |
| 2 | 30 | C |
| 3 | 10 | D |

Essentially, I would like a view that ignores the location of the products, but just aggregates the total Amount for each product.

So in this instance, I'd end up with the below. What is the best way to achieve this? A view? I'm very new to SQL and muddling through at the moment!

6yt4nkrj

6yt4nkrj1#

Thanks to CharlieFace in the comments;

SELECT Product, SUM(Amount) AS Total FROM YourTable GROUP BY Product

相关问题