Professional Documents
Culture Documents
regions.
It is interesting because this info could lead to changes in service offerings in
some regions if any of the services are found to be severely underused in those
regions
, and more business can be generated as the result.
SELECT r.reg_name
, p.service_id
, COUNT(p.purch_id) as cnt
FROM Customers c
LEFT JOIN Purchases p
ON c.cust_id = p.cust_id
LEFT JOIN Regions r
ON c.region_id = r.region_id
GROUP BY r.reg_name, p.service_id
ORDER BY cnt;
SELECT t.cust_id
, SUM(t.amount) as revenue
FROM Transactions t
LEFT JOIN Purchases p
ON t.purch_id = p.purch_id
WHERE p.purch_date BETWEEN ‘2017-01-01’ AND DATE.NOW()
AND p.service_id = 2
GROUP BY t.cust_id
ORDER BY revenue;