Guest User

Untitled

a guest
Jul 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. SELECT
  2. accounts.username, SUM(account_template_service_type_addons.units + IFNULL(service_addons.units, 0))
  3. FROM
  4. accounts
  5. JOIN account_template_instances
  6. ON (account_template_instances.account_id = accounts.id)
  7. JOIN account_template_service_types
  8. ON (account_template_service_types.account_template_id = account_template_instances.account_template_id)
  9. JOIN account_template_service_type_addons
  10. ON (account_template_service_type_addons.account_template_service_type_id = account_template_service_types.id)
  11. JOIN service_type_addons
  12. ON (account_template_service_type_addons.service_type_addon_id = service_type_addons.id)
  13. JOIN services
  14. ON (account_template_service_types.service_type_id = services.service_type_id)
  15. LEFT JOIN service_addons
  16. ON (service_addons.service_id = services.id)
  17. WHERE
  18. account_template_service_types.service_type_id = 1
  19. AND
  20. account_template_service_type_addons.service_type_addon_id = 1
  21. AND
  22. services.account_template_instance_id = account_template_instances.id
  23. AND
  24. services.service_type_id = 1
  25. GROUP BY
  26. username
Add Comment
Please, Sign In to add comment