在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/數(shù)據(jù)庫/ mysql 引號變成字段問題

mysql 引號變成字段問題

突然出現(xiàn)一個引號變成字段問題

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`)

把其中的

"%Y-%m-%d"

變成單引號

'%Y-%m-%d'

mysql 版本5.7.18 不知道這個是什么原因引起的?要如何解決呢?

回答
編輯回答
忘了我

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,這么用沒問題?等同數(shù)學公式created_at >= 1987

2017年9月29日 09:01
編輯回答
孤星

沒有發(fā)現(xiàn)你說的問題,日期是字符串引號括起來

SELECT
    count(id) total ,
    DATE_FORMAT(created_at , "%Y-%m-%d") time
FROM
    `user`
WHERE
    `created_at` >= "2017-06-24" # 注意這里的2017-06-24,引號括起來
AND `created_at` <= "2018-07-04"
GROUP BY
    `time`

注意這里的2017-06-24,引號括起來

注意這里的2018-07-04,引號括起來

另外就是,你用 DATE_FORMAT其實很消耗性能,還不如把你要查詢的日期先轉(zhuǎn)換成int類型再取查數(shù)據(jù)。

2017年8月23日 22:55
編輯回答
孤巷
sql_mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI"

這個后面多了一個ANSI就會出現(xiàn)我說的那個問題,現(xiàn)在去掉就不會了

2017年6月8日 03:24