mysql - mysql date_format() 或 str_to_date() 在 where 子句中
问题描述
我已经查看了名为“销售视图”的视图
select * from SalesView;
我想从 SalesView 中获取 order_date 为 9-OCT-2019 的记录。订单日期的值由 GUI 以 DD-MM-YYYY 格式提供。
我试过了,
select *
from salesView
where str_to_date(order_date,'%d-%m-%Y') = str_to_date('09-10-2019','%d-%m-%Y')
order by oID;
我也尝试过 date_format() 而不是 str_to_date(),但它什么也没返回。
解决方案
检查你的 where 子句
where str_to_date(order_date,'%d-%m-%Y') = str_to_date('09-10-2019','%d-%m-%Y')
将 order_date 的格式替换为数据库存储它的格式。YYYY-MM-DD
where str_to_date(order_date,'%Y-%m-%d') = str_to_date('09-10-2019','%d-%m-%Y')
推荐阅读
- c++ - 优先队列未正确排序
- javascript - 为什么 svg 加载仅在 Google Chrome 中延迟
- c# - 如何从现有列表中获取与关键字匹配并忽略大小写的项目列表(不区分大小写)?
- python - 时间乘法矩阵和向量
- r - 如何让 R 将这些单元格读取为空白而不是 NA?
- ruby - ruby 编码有什么问题?
- openssl - 通过 HTTPS 为 NiFi 生成自签名证书
- mysql - MySQL 一对多关系将值从一个表添加到另一个表
- php - 使用PHP,当我只知道“aaa”时,如何从“string1 string2 aaa-bbb string3”中获取子字符串“aaa-bbb”?
- python - 为什么当我告诉 django 这样做时我没有创建令牌?