I have a question that uses this DML statement
SELECT SupplierID, COUNT(*) AS TotalProducts
FROM Products
GROUP BY SupplierID;
I'm trying to get the same results without using "Group By". I can use a table variable or a temp table, with Insert and Update if needed. Also, using While and IF-Else is allowed.
I'm really lost any help would be awesome. Thanks SO Community.
This is used in SQL Server. Thanks again.
You can always use SELECT DISTINCT
with window functions:
SELECT DISTINCT SupplierID,
COUNT(*) OVER (PARTITION BY SupplierId) AS TotalProducts
FROM Products;
But GROUP BY
is the right way to write an aggregation query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With