SQL HELP PLEASE Write a query to generate a ranked list of e
SQL HELP PLEASE
Write a query to generate a ranked list of employees based upon the amount of money brought in via customer invoices for which they were the support representative. The result set (see figure below) should have the following fields (in order) for all employees (even those that did not support any customers): ID (e_id), first name (e_first_name), last name (e_last_name), title (e_title), and invoice total (total_invoices). The rows should be sorted by the invoice total (greatest first), then by last name (alphabetically), then first name (alphabetically). The invoice total should be preceded by a dollar sign ($) and have two digits after the decimal point (rounded, as appropriate); in the case of employees without any invoices, you should output a $0.00, not NULL. You may find it useful to look at the IFNULL, ROUND, and PRINTF functions of SQLite
Album Artist Albumld Artistld Title Name L Artist ld PlaylistTrack Playlist playlistId stid Trackld Name Employee n Employ eeld e-m Customer Last Name CustomerId First Name FirstName Title LastName ReportsTo Com BirthDate Address HireDate City Address State City Country State PostalCode Country Phone PostalCode Fax Phone Email Fax Email supportRepld Track Trackld Name Albumld MediaTypeld Genreld Composer Milliseconds Bytes Unit Price Invoice Line Invoice Lineld nvoiceld Trackld UnitPrice Quantity Invoice Invoice Id L customer ld Invoice Date Billing Address BillingCity Billingstate BillingCountry Billing PostalCode Total Media Type Media T Name Genre Genreld NameSolution
SELECT E.EmployeeId,E.FirstName,E.LastName,E.Title,\'$\' ||(SELECT printf(\"%.2f\", ifnull(sum(Total), 0))FROM Invoice I JOIN Customer C USING (CustomerId) WHERE C.SupportRepId = E.EmployeeId) AS total_invoices FROM Employee E ORDER BY total_invoices DESC,E.LastName,E.FirstName;