I have a table of product id's and prices at which the products sold.
Some products are listed in the table multiple times, up to hundreds or thousands of times depending on how many times the product was sold.
I want to find the Mode for each product.
I have this code:
SELECT TOP 1 with ties DATA
WHERE DATA IS Not NULL
GROUP BY DATA
ORDER BY COUNT(*) DESC
found here: http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/calculating-mean-median-and-mode-with-sq/
But that only works to calculate for 1 product whereas I need to calculate it for each productid (I have over 1,000 productids in the table)
What is the best way to do this?
I am using SQL Server 2012
Thanks in advance.