sql-server - 具有 NULL 值的 FIRST_VALUE 和 LAST_VALUE
问题描述
我想使用 FIRST_Value 和 LAST_Value SQL Server 获得前 2 名昂贵的书和至少 2 种昂贵的书价格
Null 的存在给出了不正确的 Min 价格值,我希望 Min 价格忽略 Null
Select top 2 FIRST_VALUE(price) Over(Order by price) as MinPrice,
FIRST_VALUE(title) Over (order by price) as MinName,
LAST_VALUE(price) Over (order by price desc) as MaxPrice,
LAST_VALUE(title) over (Order by price desc) as MaxName
from titles;
获取此输出
MINPrice MINName Maxprice MaxName
NULL The Psychology of Computer $22.95 But is it Friendly?
NULL The Psychology of Computer $21.59 Computer Phobic and
我期望的结果应该在哪里
Minprice MinName Maxprice Maxname
$2.99 The Gourmet Microwave $22.95 But is it Friendly?
$2.99 You can Combat stress $21.59 Computer Phobic and
那么如何从 Min price 中消除 NULL
解决方案
SELECT min(value) FROM table WHERE value IS NOT NULL.
它应该是这样的。
推荐阅读
- python - 获取Django app中上传文件的文件大小
- algorithm - n 楼梯/阶梯攀登问题:无法概念化为什么 T(n) = T(n-1) + T(n-2)
- angular - 服务工作者不在 Angular 8 中工作
- c# - 通过将“[Serializable]”属性添加到 C# 类,消息大小可以增加多少?
- laravel - 在不选择图像的情况下更新会出错(Laravel)
- javascript - 如何从 JSON 对象填充列表并创建树视图 - JavaScript
- html - Flex 项目不在 IE 中居中
- kubernetes - Kubernetes 中 hostPath 的缺点
- docker - Docker撰写部署停机时间与capistrano?
- javascript - 从 InAppBrowser 读取 localStorage