我得到了:
YEAR MONTH DAY SHARES_TRADED NUM_TRADES DOLLAR_VOLUME
---------- ---------- ---------- ------------- ---------- -------------
rank
----------
2010 1 4 1425504460 4628115 3.8495E+10
1
2010 1 5 1754011750 5394016 4.3932E+10
2
2010 1 6 1655507953 5494460 4.3817E+10
3
但我想得到:
YEAR MONTH DAY SHARES_TRADED NUM_TRADES DOLLAR_VOLUME
---------- ---------- ---------- ------------- ---------- -------------
2010 1 4 1425504460 4628115 3.8495E+10
2010 1 5 1754011750 5394016 4.3932E+10
2010 1 6 1655507953 5494460 4.3817E+10
我正在使用等级函数,如:
select year, month, day, shares_traded,num_trades, dollar_volume, rank() over (partition by year, month order by day asc) "rank" from nyse;
我想使用等级功能,但我不希望等级出现。是否有办法?
答案 0 :(得分:2)
假设您打算在其他地方使用rank(),请使用CTE
with CTE as
(
select year, month, day, shares_traded,num_trades, dollar_volume, rank() over (partition by year, month order by day asc) "rank" from nyse
)
select year, month, day, shares_traded,num_trades, dollar_volume
from CTE
order by CTE."rank"
答案 1 :(得分:2)
使用子查询:
SELECT year,
month,
day,
shares_traded,
num_trades,
dollar_volume
FROM (
select year,
month,
day,
shares_traded,
num_trades,
dollar_volume,
rank() over (partition by year, month order by day asc) "rank"
from nyse
)
WHERE "rank" = 1; -- Or whatever filtering you want to do on rank.