在程序里使用sql的时候遇到这样一个问题,有两个字段 opDate 和 cuDate 数据库中都是Varchar类型,值的范例为: opDate -- > 2009-12-01 00:00:00.0 cuDate--> 20091201 ,但在sql 中必须要opDate=cuDate 这种操作 .那么怎么才能匹配上相同天呢?我们需要做时间转换。
select * from tableA where name='t' and dataType=0 and (select str_to_date(cuDate , '%Y%m%d'))= (select str_to_date(opDate , '%Y-%m-%d')) 也就是通过mysql的函数把字符串转换成日期进行比较。