Guest User

Untitled

a guest
Jun 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. Date ID wt value
  2. 01/01/2012 100 0.50 60
  3. 01/01/2012 101 0.75
  4. 01/01/2012 102 1.00 100
  5. 01/02/2012 201 0.50
  6. 01/02/2012 202 1.00 80
  7.  
  8. select date,id, sum(case when value is not null then value*wt else 0
  9. end)/nullif(sum(case when value> 0 then wt else 0 end),0) as wt_avg
  10. from table
  11. group by date, id
Add Comment
Please, Sign In to add comment