I have a invoices table like this:
| Group | Client | Invoice Amount |
| ------------ | ------------ | ------------ |
| Group 1 | John | 250 |
| Group 1 | John | 250 |
| Group 2 | Debra | 250 |
I would like to display the report as:
Group | Client | Invoice Amount |
---|---|---|
Group 1 | John | 500 |
Group 2 | Debra | 250 |
Essentially I'd like to sum by group.
To achieve this, the code that I've tried is:
select dbo.Clients.Groups,
dbo.ClientInvoices.Amount
from dbo.Clients
INNER JOIN dbo.ClientInvoices ON dbo.Clients.Groups = dbo.Clients.Groups
Is anyone able to advise how to achieve this?
2条答案
按热度按时间wfsdck301#
You can use SUM and GROUP BY
Here's an example (you might need to change the column names for your exact use case)
epggiuax2#
You can try using a group by or Window function for solve your problem
You can to insert the basic data with the following codes