What does the following query calculate? SELECT product, sales / SUM(sales) OVER () * 100 AS pct FROM sales_table
SQL Data AnalystMedium
SQL Data Analyst — Medium
What does the following query calculate? SELECT product, sales / SUM(sales) OVER () * 100 AS pct FROM sales_table
Explanation
The query calculates each product's sales as a percentage of the grand total by dividing each product's sales by the sum of all sales in the table and multiplying by 100.