【发布时间】:2020-04-25 23:52:58
【问题描述】:
我正在从 MySQL 数据库中的 JSON 字段进行查询,目前该字段似乎工作正常。它给了我记录。但我的问题是我无法选择 JSON 字符串中的项目日期在某个日期之前的位置。它似乎在给定日期之前和之后给了我记录,这显然不起作用。这是我到目前为止的代码:-
select
user_id,
json_extract(user_profile, "$.gender") as gender,
json_extract(user_profile, "$.dateofbirth") as dateofbirth
from user_profiles
where json_extract(user_profile, "$.gender") = "Female"
and json_extract(user_profile, "$.dateofbirth") < "06/15/1988"
我考虑使用我考虑使用 DATE_FORMAT() 例如:-
where json_extract(user_profile, "$.gender") = "Female"
date_format(json_extract(user_profile, "$.dateofbirth"), "%d/%m/%Y") < "06/15/1988"
但那只会让我没有记录。 有什么办法可以让 MySQL 从我查询的 JSON 字符串中理解日期格式?
【问题讨论】:
-
可能是个愚蠢的问题数据库中 dateofbirth 列中的日期是什么格式
-
格式为dd/mm/yyyy
标签: mysql json date-formatting json-extract