Question: Sapling received access to a client database. The client is a paint and paint supplies distributor, and they record all their sales transactions in a
- Sapling received access to a client database. The client is a paint and paint supplies distributor, and they record all their sales transactions in a "live_sales" table, holding information on sales line items and their respective brand, price, quantities, discounts, etc. Could you describe what the following SQL query does?
SELECT
Brand,
YEAR(date_datetype),
MONTH(date_datetype),
SUM(amount) AS GrossSales,
SUM(lineitemdiscount) AS Discount,
(COALESCE(SUM(amount), 0) + COALESCE(SUM(lineitemdiscount), 0)) AS NetSales,
SUM(est_extended_cost) AS Cost,
(COALESCE(SUM(amount), 0) + COALESCE(SUM(lineitemdiscount), 0) - COALESCE(SUM(est_extended_cost), 0)) AS GrossMargin,
SUM(quantity) AS Volume
FROM
live_sales
GROUP BYBrand , YEAR(date_datetype) , MONTH(date_datetype);
Step by Step Solution
There are 3 Steps involved in it
The given SQL query retrieves aggregated sales information from the livesales table for each brand y... View full answer
Get step-by-step solutions from verified subject matter experts
