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

  1. 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

1 Expert Approved Answer
Step: 1 Unlock

The given SQL query retrieves aggregated sales information from the livesales table for each brand y... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!