1

It's a bit difficult to explain what I'm trying to do (sorry for the hard to read title), but basically I want to sum repeat rows like so:

Table A:

EntryID| Country | Region | Sales 
101    | USA     | North  | $10
102    | USA     | North  | $5
103    | USA     | South  | $15
104    | USA     | South  | $10
105    | CHINA   | North  | $5
106    | CHINA   | North  | $5
107    | CHINA   | South  | $10
108    | CHINA   | South  | $20

Desired Output:

EntryID| Country | Region | Sales 
101    | USA     | North  | $15
103    | USA     | South  | $25
105    | CHINA   | North  | $10
107    | CHINA   | South  | $30

How can I do this?

2
  • what type is sales column? Commented Dec 28, 2016 at 18:21
  • In your desired output, are you sure that EntryID is correct for each row? (I would imagine more than one EntryID for some rows...) Commented Dec 28, 2016 at 18:24

2 Answers 2

4

The SQL statement has to look like:

SELECT MIN(EntryID) AS EntryID,
  Country,
  Region,
  SUM(Sales) AS Sales
FROM TABLE
GROUP BY Country,
  Region
Sign up to request clarification or add additional context in comments.

1 Comment

Formatted the query :)
0

Details are lacking, but it sounds like a simple GROUP BY to me:

select min(EntryID), Country, Region, sum(sales)
  from tbl
 group by Country, Region

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.