我尝试进行此查询
创建一个视图,列出过去 6 个月内购买次数最多的 10 种产品。
CREATE VIEW Top10product6month_VW AS
SELECT ProductID
FROM (select ProductID,SYSDATE - OrderDate AS OrderAge
from DD_OrderLine
WHERE SYSDATE - OrderDate <= 183)
Where ROWNUM <= 10;
我无法获得top10。
我的 OrderLine 表是
CREATE TABLE DD_OrderLine
(
OrderDate DATE,
SUMofPrice NUMBER(8,2),
OrderID NUMBER(6),
ProductID NUMBER(6),
CONSTRAINT DD_orderid_productid_pk PRIMARY KEY (OrderID,ProductID )
);
和记录是
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/25', 'yyyy/mm/dd')),000010.00,1,000117,001116);
--
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/14', 'yyyy/mm/dd')),000010.00,1,000118,001112);
--
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/14', 'yyyy/mm/dd')),000010.00,1,000118,001111);
--
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/15', 'yyyy/mm/dd')),000010.00,1,000119,001111);
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/15', 'yyyy/mm/dd')),000010.00,1,000119,001112);
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/24', 'yyyy/mm/dd')),000010.00,1,000120,001115);
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/24', 'yyyy/mm/dd')),000010.00,1,000120,001114);
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/24', 'yyyy/mm/dd')),000010.00,1,000120,001113);
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/24', 'yyyy/mm/dd')),000010.00,1,000120,001112);
----
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/24', 'yyyy/mm/dd')),000010.00,1,000120,001111);
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/24', 'yyyy/mm/dd')),000010.00,1,000120,001116);
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/24', 'yyyy/mm/dd')),000010.00,1,000120,001117);
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/30', 'yyyy/mm/dd')),000010.00,1,000121,001112);
INSERT INTO DD_OrderLine (OrderDate,SUMofPrice, QuantityPurchased,OrderID,ProductID)
VALUES ((to_date('2013/9/30', 'yyyy/mm/dd')),000010.00,1,000122,001112);
有什么方法可以统计 ProductID 并进入前 10 名?
太感谢了