创建时间是timestamp类型,根据年月日的日期是无法查询到的,所以我们需要通过转换数据格式进行查询。
查询一段时间内的数据。
一、beteen...and
SELECT * FROM weigh WHERE Business_card_number LIKE '华A%'
AND DATE_FORMAT(N_time,'%Y-%m-%d %H:%i:%s') BETWEEN '2022-03-28 15:00:00' AND '2022-05-24 24:00:00'
二、大于号and小于号
SELECT * FROM weigh WHERE Business_card_number LIKE '华A%'
AND DATE_FORMAT(N_time,'%Y-%m-%d %H:%i:%s') >= '2022-03-28 15:00:00'
AND DATE_FORMAT(N_time,'%Y-%m-%d %H:%i:%s') <= '2022-05-24 24:00:00'
三、转换成UNIX_TIMESTAMP
SELECT * FROM weigh WHERE Business_card_number LIKE '华A%'
AND UNIX_TIMESTAMP(N_time) BETWEEN UNIX_TIMESTAMP('2022-03-28 15:00:06') AND UNIX_TIMESTAMP('2022-05-24 16:43:06')
2022-05-24 16:43:06没有错误,但是查询就不对,复制数据库里的值改动一下就对了,迷茫。。。