mysql - 使用mysql Like查询从表中检索十进制值
问题描述
我想从表中检索记录,所有记录都是(宽度 x 高度)格式的十进制值
使用like子句我想获取数据但查询不起作用
Table:
id widthheight
1 17.14X12.41
2 23.4X39.8
select * from test where widthHeight like '%17X12%'
解决方案
如上所述,创建两列“宽度”和“高度”
select * from (
select
id,
SUBSTRING_INDEX(widthHeight, 'X', 1) width,
SUBSTRING_INDEX(widthHeight, 'X', -1) height
from mytable) x
where floor(x.width)=17 and floor(x.height)=12
您的原始查询不起作用,因为您应该这样做:
select *
from mytable
where widthHeight like '%17%' and widthHeight like '%12%'
推荐阅读
- reactjs - 使用 HOC 测试反应组件方法
- python - ValueError:确保您指定了正确的输入图像、输入类型、输出类型和/或输出图像路径
- c++ - 如何在多个源文件中将 C++ 堆栈实现为全局变量?
- android - 在挂载 sd 卡的设备上读取和写入文件时出现问题
- youtube-api - 通过嵌入 YouTube 视频被 CORS 政策错误阻止
- c# - Protobuf - 替换通用集合
- javascript - 如何在测试中读取 jest 配置值?
- chart.js - Chart.js 从轴移动图表的起始位置
- azure - Azure 信号中的 serverExceptions 和 Exceptions 有什么区别?
- scala - Scala Seq vs List vs MutableList 性能(foldLeft)