roganhamby

Money Paid to Other Libraries Report

Jan 16th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select sum(payment.amount), count(payment.id), sum(payment.amount)/count(payment.id) as "Average Transaction", staff_org.shortname as "Payment Library", usr_org.shortname as "User Home Library"
  2. from money.cash_payment payment
  3. join money.billable_xact bills on bills.id = payment.xact
  4. join actor.usr usr on usr.id = bills.usr
  5. join actor.org_unit aoux on aoux.id = usr.home_ou
  6. join actor.org_unit usr_org on usr_org.id = aoux.parent_ou
  7. join actor.usr usr2 on usr2.id = payment.accepting_usr
  8. join actor.org_unit aouy on aouy.id = usr2.home_ou
  9. join actor.org_unit staff_org on staff_org.id = aouy.parent_ou
  10. where staff_org.id != usr_org.id
  11. group by 4, 5
  12. order by 4, 5
  13. ;
  14.  
  15. select sum(payment.amount), count(payment.id), trunc(sum(payment.amount)/count(payment.id),2) as "Average Transaction", staff_org.shortname as "Payment Library"
  16. from money.cash_payment payment
  17. join money.billable_xact bills on bills.id = payment.xact
  18. join actor.usr usr on usr.id = bills.usr
  19. join actor.org_unit aoux on aoux.id = usr.home_ou
  20. join actor.org_unit usr_org on usr_org.id = aoux.parent_ou
  21. join actor.usr usr2 on usr2.id = payment.accepting_usr
  22. join actor.org_unit aouy on aouy.id = usr2.home_ou
  23. join actor.org_unit staff_org on staff_org.id = aouy.parent_ou
  24. where staff_org.id != usr_org.id
  25. group by 4
  26. order by 4
  27. ;
Add Comment
Please, Sign In to add comment