Teradata 中的排名- SQL
Ranking in Teradata- SQL
我正在尝试使用 rank() over 函数对我的销售数据进行排名。这是我的代码:
Select
Category as CAT
,units*cost as COST_SALES
,units*retail as RETAIL_COST
,units as UNITS_SOLD
,RANK() OVER (PARTITION BY 1 ORDER BY 3 DESC ) AS RANKING
from Table
Where date between current_date-7 and current_date
group by 1
当我得到我的结果时,它是无序的并且在所有类别中显示排名 1。
您不能在 window 函数中使用列引用。您需要明确命名列:
Select Category as CAT, units*cost as COST_SALES, units*retail as RETAIL_COST,
units as UNITS_SOLD,
RANK() OVER (PARTITION BY Categroy ORDER BY units*retail DESC ) AS RANKING
from Table
Where date between current_date-7 and current_date
group by Category;
我正在尝试使用 rank() over 函数对我的销售数据进行排名。这是我的代码:
Select
Category as CAT
,units*cost as COST_SALES
,units*retail as RETAIL_COST
,units as UNITS_SOLD
,RANK() OVER (PARTITION BY 1 ORDER BY 3 DESC ) AS RANKING
from Table
Where date between current_date-7 and current_date
group by 1
当我得到我的结果时,它是无序的并且在所有类别中显示排名 1。
您不能在 window 函数中使用列引用。您需要明确命名列:
Select Category as CAT, units*cost as COST_SALES, units*retail as RETAIL_COST,
units as UNITS_SOLD,
RANK() OVER (PARTITION BY Categroy ORDER BY units*retail DESC ) AS RANKING
from Table
Where date between current_date-7 and current_date
group by Category;