SQL查询什么以获取今天更新的所有元组(CollectionDate列中提供的日期为DD-MMM-YY格式)?

时间:2019-07-18 16:35:13

标签: mysql sql

这是桌子的样子

ID             MSG_TYPE       CollectionDate
515587         GenOut         21-FEB-19 04.09.57.325772000 PM
515588         GenOut         18-JUL-19 01.06.15.307068000 PM
515589         GenOut         22-AUG-18 03.20.15.307069290 PM
515590         GenOut         18-JUL-19 12.03.09.873288000 PM

预期结果

ID             MSG_TYPE       CollectionDate
515588         GenOut         18-JUL-19 01.06.15.307068000 PM
515590         GenOut         18-JUL-19 12.03.09.873288000 PM

1 个答案:

答案 0 :(得分:1)

一个where子句似乎足够。您应该真正修复列,以便将其存储为善意日期,而不是字符串。

也就是说,您可以使用:

where collectiondate like concat(date_format(curdate(), '%d-%b-%y'), '%')

或者:

where str_to_date(left(collectiondate, 9), '%d-%b-%y') = curdate()