sql - 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 返回许多行。解决办法是什么?
解决方案
似乎您不在乎返回哪个ORDER BY
值(无子句),为什么不
select mfc,
max(ana)
from article
where ana is not null
group by mfc
推荐阅读
- r - R - 将 CHR 转换为日期
- html - 将表格页脚固定到页面底部,同时保持列的大小正确
- javascript - 如何在 NodeJS 中使用 body.req 从输入表单中检索数据?
- mysql - 如何在 eloquent laravel 中使用别名编写 SQL 查询?
- php - MySQL 8.0.15 连接
- tensorflow - Tensorflow 数据集 - 有什么意义
- spring-kafka - 如果设置spring.kafka.listener.ack-mode=time,会重试吗?或在指定的确认模式下重试工作?
- sql - 使用嵌套表时如何避免触发器中的表发生变异,并对另一个表进行更新?
- c++-winrt - 如何在winrt中将焦点设置为Grid UIElement?
- python-3.x - Python中的类和函数参数使用问题