sql - MySQL: sum cells in column and insert it in same table with condition -


i need sum specific cells in column condition , insert in same table

table structure:

id    user_id      type       scores 1        1         daily        10 2        1         daily        20 3        1                  500 4        1         daily         5 5        2                   200 6        3                   300 7        2         daily         23 8        1          cat          11 9        2         daily         25 10       3         daily         30 

each user have 1 "all" score (in "type" column ) , multiple "daily" scores,

how sum "daily" scores , insert in "all" row

like:

id    user_id      type       scores 1        1         daily         10 2        1         daily         20 3        1                   35 4        1         daily         5 5        2                   48 6        3                   30 7        2         daily         23 8        1          cat          11 9        2         daily         25 10       3         daily         30 

thanks,

you doing update, not insert. can use join:

update structure s join        (select user_id, sum(scores) sums         structure s         type = 'daily'         group user_id        ) ss        on s.user_id = ss.user_id     set s.scores = ss.sums     s.type = 'all'; 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -