Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Date ID wt value
- 01/01/2012 100 0.50 60
- 01/01/2012 101 0.75
- 01/01/2012 102 1.00 100
- 01/02/2012 201 0.50
- 01/02/2012 202 1.00 80
- select date,id, sum(case when value is not null then value*wt else 0
- end)/nullif(sum(case when value> 0 then wt else 0 end),0) as wt_avg
- from table
- group by date, id
Add Comment
Please, Sign In to add comment