I have a table: Othercharges
which consists of columns: code
, name
, primarykey
, groupby
, jan
I want to SUM
the values of Jan
using groupby
which is based on the Primarykey
I tried using this code:
UPDATE othercharges
SET JAN = (SELECT SUM(jan) FROM othercharges WHERE primarykey IN(groupby) and code = code)
WHERE Groupby NOT IN('NULL')
but its giving me a NULL
result because it reads it as IN('1,2,3')
not IN(1,2,3)
:
code name primarykey groupby jan
WDS Wood 1 NULL 200
FDS Food 2 NULL 100
IRN Iron 3 NULL 300
STL Steel 4 NULL 400
SUM Sum 5 1,2,3 NULL <---result
Supposed to output:
code name primarykey groupby jan
WDS Wood 1 NULL 200
FDS Food 2 NULL 100
IRN Iron 3 NULL 300
STL Steel 4 NULL 400
SUM Sum 5 1,2,3 500 <---result