試圖創建一個表格,其中包含按產品銷售的總數量,並選擇按日期分段的第三個銷售數量最高的產品。一直得到錯誤帶RANK OVER函數的列名稱無效SQL
無效列名
的別名我RANK() OVER
聲明:
select
RANK() OVER (PARTITION BY t3.orderdate order by t3.total_amt_ordered) as ranking,
t3.productid,
t3.orderdate,
t3.total_amt_ordered
from
(select
t2.productid,
t1.orderdate,
SUM(t2.orderqty) as total_amt_ordered
from
saleslt.salesorderheader t1
inner join
saleslt.salesorderdetail t2 on t1.salesorderid = t2.salesorderid
group by
productid, orderdate) t3
where
ranking = 3;
您的期望是什麼? – Teja