mysql - Replace Null value to infinite
问题描述
I have a table with field min, max and amount. The last value of the column max is always null and it denotes min value and above as per my logic. During BETWEEN query in sql I tried as:
Select t.amount from my_table t where 25000 between t.min and NVL(t.max, ~0);
Also, I tried:
Select t.amount from my_table t where 25000 between t.min and COALESCE(t.max, ~0);
None of them return me a row if the value lies between min and NULL.
解决方案
How about:
25000 between t.min and nvl(t.max, 25000)
If t.max
is null, the nvl()
function returns 25000
, which will satisfy the higher bound of the between
operator.
If the value to compare is stored in a column, say col1
, then you can do:
col1 between t.min and nvl(t.max, col1)
推荐阅读
- javascript - 如何使用 ${var} 使用 RegExp 替换模板?
- perl - Perl DBI 不区分大小写的方法
- git - 使用解决合并冲突后恢复 _remote_ 文件
- sql-server - 在 Ubuntu 中将 SQL 服务器身份验证更改为 Azure Active Directory 身份验证后,Pyodbc 连接 SQL 服务器失败
- javascript - 当我的弹出窗口显示在博客上时,如何使所有背景都无法点击?
- r - 如何修复“无效因子水平”?
- web-services - 如何更改 SAP WSDL 标签或修改 Web 服务?
- vba - 如何输入字符串变量介绍 FormulaU?
- javascript - 获取两列的最后一行之间的差异,以便向单元格添加值,使列的长度相等
- javascript - Javascript从字符串中获取对象