DEV Community

Discussion on: SQL Math Functions with Use Cases

Collapse
 
aarone4 profile image
Aaron Reese

If you need to include more information than just the grouped filed and aggregate you can also use the OVER() syntax.

SELECT category, SQRT(SUM(sales)) AS square_root_sales
FROM products
GROUP BY category;

becomes
SELECT category, ProductName, SQRT(SUM(sales) OVER (PARTITION BY category)) AS square_root_sales_of_category
FROM products;

This will aggregate the sales by category and display the result for the product category against the product row,

Collapse
 
ashsajal profile image
Xaman

Thanks for the information Reese.