Greetings All,
I'm using the following query to pull the 3 bestselling Products over the past 7 days for a particular category.
C#/VB.NET Code:
<query name="Products" rowElementName="Product">
<sql>
<![CDATA[
SELECT DISTINCT TOP 3
s.ProductID,
s.NumSales,
s.Numpounds
FROM (
select ProductID, SUM(Quantity) AS NumSales, SUM(OrderedProductPrice) AS Numpounds
from dbo.Orders_ShoppingCart
sc
join [dbo].Orders o on sc.OrderNumber = o.OrderNumber and o.OrderDate >= dateadd(dy, -7, getdate())
group by ProductID, VariantID
) s
join [dbo].Product p with (nolock) on s.productid = p.productid
WHERE p.Deleted = 0
and p.Published = 1
and p.ProductID in ( select ProductID from dbo.ProductCategory where CategoryID = @parent )
ORDER BY s.NumSales desc
]]>
</sql>
<queryparam paramname="@parent" paramtype="runtime" requestparamname="parent" sqlDataType="int" defvalue="0" validationpattern="" />
</query>
My problem is that it sometimes returns multiple entries for the same product - because the best sellers are variants of the same product.
How would I modify the query to only return one entry for each product ID?
TTFN
BFG
P.S. Nearly done with the new design then I'll have something cool to show you all............