首页 > 解决方案 > OVER 函数和 first_value

问题描述

我有一个名为 ARTICLE 的表,其中包含许多列,特别是 MFC 和 ANA。对于每个 MFC,我想要第一个不为空的 ANA。

所以,我写了这个查询:

select mfc, first_value(ana) over(partition by mfc) as FirstAna
from article
where ana is not null

但它为每个 MFC 返回许多行。解决办法是什么?

标签: sqloraclewindow-functions

解决方案


似乎您不在乎返回哪个ORDER BY值(无子句),为什么不

select mfc,
       max(ana)
from article
where ana is not null
group by mfc

推荐阅读