ar_customers
SELECT * FROM ar_customers
| customer# | customer_name | customer_address | customer_province | customer_rating |
|---|---|---|---|---|
| 1 | bill | 123 main st. | ab | 1 |
| 2 | ed | 456 main st. | bc | 2 |
| 3 | john | 789 main st. | ab | 3 |
ar_invoices
SELECT * FROM ar_invoices
| invoice# | customer# | salesperson# | invoice_date | invoice_amount | amount_paid | current_month_interest_charges | total_interest_charges |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 2019-06-17 10:43:53.727 | 100.00 | 1.00 | 0.00 | 0.00 |
| 2 | 2 | 2 | 2019-05-28 10:43:53.727 | 50.00 | 0.00 | 5.00 | 10.00 |
| 3 | 3 | 2 | 2019-06-17 10:43:53.727 | 70.00 | 0.00 | 10.00 | 20.00 |
| 4 | 2 | 1 | 2019-07-07 10:43:53.727 | 80.00 | 0.00 | 0.00 | 0.00 |
ar_salespeople
SELECT * FROM ar_salespeople
| salesperson# | salesperson_name |
|---|---|
| 1 | bob |
| 2 | mary |
| 3 | tim |
ar_salespeople
SELECT salesperson_name, MAX([Total Sales]) AS [Highest Earner] FROM (SELECT salesperson_name, SUM(invoice_amount) AS [Total Sales] FROM ar_invoices INNER JOIN ar_salespeople ON ar_invoices.salesperson# = ar_salespeople.salesperson# GROUP BY salesperson_name) x GROUP BY salesperson_name
| salesperson_name | Highest Earner |
|---|---|
| bob | 180.00 |
| mary | 120.00 |