sql - 如何在没有最大值的情况下获得 SQL Server 上字段的最大值?
问题描述
我需要获取表字段的最大值,但我不能使用 max 或任何其他聚合函数,也不能使用游标。例如,我需要获取表 Sales 上字段金额的最大值。
解决方案
有几种方法:
1.对列进行降序排序并获得第一行:
select top 1 amount from sales order by amount DESC
2.有NOT EXISTS
:
select distinct s.amount
from sales s
where not exists (
select 1 from sales
where amount > s.amount
)
推荐阅读
- mysql - 如何在 MySQL Workbench 8.0.14 中修改 mysqldump 命令参数?
- chromecast - 带有 Widevine DRM 的 Chromecast CAF
- conditional - Maximo 处理规则
- ubuntu - 如何更改仪表板管理员
- sql-server - 尝试安装 sql server express 2014 或 2008 时如何修复“库未注册”
- r - 尽管投影相似,但光栅和形状未对齐
- git-lfs - git-lfs checkout 旧版本的二进制文件
- r - 在输入中使用 fread 函数和错误
- python - Matplotlib - 仅使用 Y 坐标突出显示已绘制图形中的点
- excel - 用word文档中的数据填充excel表