• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

SQL query to add some data from the table

I have a table. I need a SQL query to add some data from the table (MOTcalculation). I need a select query or a make table query. I need to add for every CNP and to do this automaticaly because I have more than 250 CNP. Please see the example!

MOTcalculation                                                 Query
ID      CNP      TotalMOT                      ID          CNP         TotalMOT
1         N1            15                            1             N1            22
2         C1             3                             2             C1            10
3         D3             6                             3             D3              6
4         C1             7                             4             O2            18
5         N1             4
6         N1             3
7         O2             9
8         O2             9    

Thank you!
Qw M
Qw M
  • 2
1 Solution
select row_number() OVER (ORDER BY cnp), cnp, sum(TotalMOT) from MOTCalculation group by cnp

Open in new window

Qw MAuthor Commented:
It is not working! Please see the attachment!
Jon von der HeydenCourse Leader & Managing DirectorCommented:
Select query should be fine:
SELECT MOTCalculation.CNP, Sum(MOTCalculation.TotalMOT) AS SumOfTotalMOT
FROM MOTCalculation
GROUP BY MOTCalculation.CNP;

Open in new window

Qw MAuthor Commented:
Thank you JONvdHeyden!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now