Mysql quotation marks become a field problem
suddenly a quotation mark becomes a field problem
SQLSTATE[42S22]: Column not found: 1054 Unknown column "%Y-%m-%d" in "field list" (SQL: select count(id) count,DATE_FORMAT(created_at,"%Y-%m-%d") time from `user` where `created_at` >= 2017-06-24 and `created_at` <= 2018-07-04 group by `time`)
put the
"%Y-%m-%d"
becomes single quotation marks
"%Y-%m-%d"
mysql version 5.7.18 I don"t know what caused this? How to solve it?
did not find the problem you said, the date is a string enclosed in quotation marks
SELECT
count(id) total ,
DATE_FORMAT(created_at , "%Y-%m-%d") time
FROM
`user`
WHERE
`created_at` >= "2017-06-24" -sharp 2017-06-24,
AND `created_at` <= "2018-07-04"
GROUP BY
`time`
< H1 >
notice 2017-06-24 here, enclosed in quotation marks
< / H1 >
< H1 >
notice 2018-07-04 here, enclosed in quotation marks
< / H1 >
in addition, using DATE_FORMAT
actually consumes a lot of performance, so you might as well convert the date you want to query to int first and then retrieve the data.
sql_mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI"
if you add an ANSI after this, the problem I'm talking about will appear. If you remove it now, you won't get rid of it
.
ANSI Equivalent to REAL_AS_FLOAT, PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, and (as of MySQL 5.7.5) ONLY_FULL_GROUP_BY.
ANSI_QUOTES
Treat " as an identifier quote character (like the ` quote character) and not as a string quote character. You can still use ` to quote identifiers with this mode enabled. With ANSI_QUOTES enabled, you cannot use double quotation marks to quote literal strings because they are interpreted as identifiers.
created_at
> = 2017-06-24, is it okay to use it this way? Equivalent mathematical formula created_at
> = 1987