sql - 使用 between 子句时 Sql 查询没有返回所有值
问题描述
我有一个查询:
select *
from indicatordetails
where indicator.month between 'January'and 'April'
当我运行它时,它不返回任何结果,但是当我使用时:
select *
from indicatordetails
where indicator.month between 'January'and 'march'
它返回结果。
注意:我的表格从一月到四月有结果,我会感谢任何帮助,谢谢
解决方案
你所拥有的“月”是一个字符串。的操作数between
是有序的。作为字符串,'January'
在'April'
.
用数字更容易看出这一点。这个构造:
where x between 9 and 1
永远不会返回任何结果,因为 9 > 1。如果有匹配的值,这可能会返回结果:
where x between 1 and 9
我的建议是仅将此列与in
or一起使用=
:
where indicator.month in ('January', 'February', 'March', 'April')
推荐阅读
- matplotlib - 减小点大小散点图
- wpf - 如何在 DataGrid 中获取选定的组合框条目?(PowerShell WPF)
- android - 如何以编程方式更改“自动模式”屏幕亮度?
- entity-framework-core - ASP.Net Core & EF Core:递归地包含子元素并映射到视图模型
- crystal-reports - 在哪里可以找到 Crystal Reports 2011 或 Crystal Reports for .NET Framework 4.0 文档?
- python - 将 Meraki SDK 导入 python Azure 函数应用时出现 HTTP 500 错误
- javascript - 使用 npm live-server 时是否会清除 localStorage?
- nginx - 如何将 NGINX 中的特定 URL/Regex 映射到代理地址
- html - 中心的响应式 div。每边的 Px div
- wpf - 自定义 MenuItem 控件模板