18. Drug Profit by Product

Easy

drug_sales(product_id, manufacturer, sales, cogs)

Return each product's profit, meaning sales minus cost of goods, as product_id, manufacturer and profit, highest profit first. Break ties by product_id.

Some products lose money, and they belong in the result at the bottom rather than being filtered out.

Tables

drug_sales

product_id  manufacturer  sales      cogs
----------  ------------  ---------  --------
1           Acme          100000.00  40000.00
2           Acme          50000.00   80000.00
3           Borne         70000.00   70000.00
4           Borne         90000.00   30000.00
5           Cole          60000.00   60000.00

Expected result

product_id  manufacturer  profit
----------  ------------  ---------
1           Acme          60000.00
4           Borne         60000.00
3           Borne         0.00
5           Cole          0.00
2           Acme          -30000.00

Sign in to write and run your own code.

Write one SELECT query