[英]Sql Query does not return the wanted value
I am executing the following query 我正在执行以下查询
SELECT * FROM `temp` WHERE date_of_approval > "16-12-2015"
I want to get all record where the date is greater than "16-12-2015" but it displays all rows which are greater that "16" and not greater than "16-12-2015" 我想获取日期大于“ 16-12-2015”的所有记录,但它显示大于“ 16”且不大于“ 16-12-2015”的所有行
In your table you store the date in the dd-mm-yyyy
format so it is compulsory to convert into standard date format first then its compare with dates. 在表中,您以
dd-mm-yyyy
格式存储日期,因此必须先转换为标准日期格式,然后再将其与日期进行比较。
SELECT * FROM `temp`
WHERE STR_TO_DATE(date_of_approval,'%d-%m-%Y') > STR_TO_DATE('16-12-2015','%d-%m-%Y');
OR 要么
SELECT * FROM `temp`
WHERE STR_TO_DATE(date_of_approval,'%d-%m-%Y') > '2015-12-16';
My recommendation. 我的建议。 Always use ISO standard date formats.
始终使用ISO标准日期格式。 These are accepted by most databaes:
这些被大多数数据库接受:
SELECT t.*
FROM `temp` t
WHERE date_of_approval > '2015-02-16'
Also, use single quotes for string and date constants in SQL statements. 另外,对SQL语句中的字符串和日期常量使用单引号。 This is the standard delimiter for strings.
这是字符串的标准分隔符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.