为什么CAST
在这个MySQL查询中不起作用?
SELECT MAX(Signups) AS Max,
MIN(Signups) AS Min,
CAST(ROUND(AVG(Signups),2) AS VARCHAR(3)) AS Avg
FROM
(
SELECT COUNT(1) AS Signups,
DATE_FORMAT(JoinDate, "%Y-%m-%d") AS Date
FROM users
GROUP BY Date
) z
为什么我收到此错误?
#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near
'VARCHAR(3)) AS Avg FROM ( ' at line 2
答案 0 :(得分:4)
这可能是由于MySQL bug #34564: CAST does not accept varchar type。
尝试转换为其他类型,如下所示:
CAST(ROUND(AVG(Signups),2) AS CHAR(3)) AS Avg
答案 1 :(得分:0)
将VARCHAR
更改为CHAR
可解决问题