Link to home
Start Free TrialLog in
Avatar of Qw M
Qw MFlag for United States of America

asked on

SQL query to add some data from the table

Hi!
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!
Avatar of bmatumbura
bmatumbura

Try
select row_number() OVER (ORDER BY cnp), cnp, sum(TotalMOT) from MOTCalculation group by cnp

Open in new window

Avatar of Qw M

ASKER

It is not working! Please see the attachment!
untitled.JPG
ASKER CERTIFIED SOLUTION
Avatar of Jon von der Heyden
Jon von der Heyden
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Qw M

ASKER

Thank you JONvdHeyden!