Given a Postgres SQL tables, with these properties:
Ticket(id, user_id, opened _at, closed_at)
User(id, name, address, company_id)
Company (id, name, address)
Purchase(id, company_id, time, amount) Write a SQL query to list companies whose average ticket close time is greater than 24 hours ordered by the company with the greatest response time. For those same companies, please also include the total amount of purchases they have spent in the past month if their total purchase amount is at least one standard deviation above that of the
average purchase amount across all companies. There should be exactly 3 paragraphs separated by the markdown divider: ***.
user