Select 如果行有不同的值,max(date) 不起作用,我只想获取日期最高的行
Select max(date) does not work if the rows have different values, I only want to fetch the row with the highest date
这是代码:
select security,max(dte),close,ask,bid,mid from k$prices
where to_char(dte,'MON-YYYY') = 'JAN-2021'
group by security,close,ask,bid,mid,dte
order by security,dte desc
结果如下:我只想得到2行,其中每个证券的日期最高(436 January 5和448 January 29)但是因为字段的值不同,所有行仍然是显示。请帮我。谢谢
您可以在内联视图 t 中首先对所有行进行排名,然后 select 仅排名为 1 (rnb = 1) 的行
select security, dte, close, ask, bid, mid
from (
select security, dte, close, ask, bid, mid, row_number()over(partition by security order by dte desc) rnb
from your_table
)t
where rnb = 1
;
这是代码:
select security,max(dte),close,ask,bid,mid from k$prices
where to_char(dte,'MON-YYYY') = 'JAN-2021'
group by security,close,ask,bid,mid,dte
order by security,dte desc
结果如下:我只想得到2行,其中每个证券的日期最高(436 January 5和448 January 29)但是因为字段的值不同,所有行仍然是显示。请帮我。谢谢
您可以在内联视图 t 中首先对所有行进行排名,然后 select 仅排名为 1 (rnb = 1) 的行
select security, dte, close, ask, bid, mid
from (
select security, dte, close, ask, bid, mid, row_number()over(partition by security order by dte desc) rnb
from your_table
)t
where rnb = 1
;