December 13, 2011 at 10:20 am
ok I have the problem:
Create a VIEW called TopSales that shows the TOP 10 percent of sales. Verify the results of the
view in a SELECT clause. The problem is it is not adding up the qty for each distinct productid. I can't figure out how to make it do that. Supposedly it is only supposed to return two rows.
IF OBJECT_ID ('TopSales') IS NOT NULL
DROP VIEW TopSales;
GO
USE TSQLFundamentals2008;
GO
CREATE VIEW TopSales AS
SELECT TOP (10) PERCENT qty, productid
FROM Sales.OrderDetails
GROUP BY qty, productid ORDER BY qty DESC;
GO
SELECT * FROM TopSales
December 13, 2011 at 10:22 am
Edit - missed something.
Edit 2 Wow Can't read today!
SELECT TOP ( 10 ) PERCENT
SUM(qty) AS SumQty
, productid
FROM
Sales.OrderDetails
GROUP BY
productid
ORDER BY
SumQty DESC ;
December 13, 2011 at 4:55 pm
Please post all further questions in this thread.
So it's all good now?
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply