0

I need to create to query using the data shown in the image below. I need to sum the Data field based on the ID column.

enter image description here

Expected Result:

enter image description here

I need to get distinct ID field and sum the Data column Note: location and Trc are the same for particular ID.

Thanks in advance.

3
  • 2
    for ID 30 you have 2 different commessa's but sum everything for ID 30. which commesa do you need in the result? Commented Apr 28, 2017 at 12:10
  • Show us your current query attempt. Commented Apr 28, 2017 at 12:11
  • No need of Commesa value. @Kevin Commented Apr 28, 2017 at 12:20

2 Answers 2

1

Use aggregate function sum in data column

select ID,location,Trc,Commessa sum(data) From Table
Group by ID,location,Trc,Commessa
Sign up to request clarification or add additional context in comments.

2 Comments

Id 30 have different commessa values.
This query will return 4 rows, using the sample data. (Two rows for id 30.)
0

Try this:-

Select ID,location,Commessa,Trc, sum(Data) as Data
from
YOUR_TABLE_NAME
group by ID, location, Commessa, Trc

8 Comments

Id 30 have different commessa values.
@jarlh location, Commessa, Trc are same for particular ID he noted this
@ZaynulAbadinTuhin but that is not what you see on his sample data shown in the image
This query will return 4 rows, using the sample data, two rows for id 30.
@Kevin that could be his type mistake
|

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.