sql - Group Columns based on Row ID -


i have table pulling data, like:

id    fid   value 001   20    200 001   20    400 001   50    600 002   50    100 

how write query column each row id sum value's?

for example, want return following:

id     20     50 001    600    600 002    null   100 

a pattern this:

select   id,   sum(case when fid = 20 value end) sum20,   sum(case when fid = 50 value end) sum50 --extend adding more case when rows   table group id 

..has advantage of working in databases don't support pivot syntax.

if you'd pivot syntax:

select id, [20], [50] --extend providing more values in square brackets   table pivot (   sum(value)   fid in ([20], [50]) --extend providing more values in square brackets ) pvt 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -