嘿伙计们,我的问题很简单:我有这个要求:
->prepare("SELECT
CONCAT(YEAR(`p`.`created_account`), '-', MONTH(`p`.`created_account`)) AS `month`
FROM
`profile` AS `p`
GROUP BY
YEAR(`p`.`created_account`), MONTH(`p`.`created_account`)");
我在 mysql 5 中并且可以工作,但我升级到 mysql 8 并且知道我有这个错误:
object(Doctrine\DBAL\Exception\SyntaxErrorException)#707 (8) { ["driverException":"Doctrine\DBAL\Exception\DriverException":private]=> object(Doctrine\DBAL\Driver\PDOException)#766 (10) { ["errorCode":"Doctrine\DBAL\Driver\PDOException":private]=> int(1064) ["sqlState":"Doctrine\DBAL\Driver\PDOException":private]=> string(5) "42000" ["message":protected]=> string(282) "SQLSTATE[42000]: 语法错误或访问冲突:1064 您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本对应的手册以获取正确的语法使用'FROM
profile
ASp
GROUP BY YEAR(p
.created_account
), MONTH(p
.`created_a' at line 1" ["string":"Exception":private]=>string(0) "" ["code":protected]=> string(5) "42000" ["file":protected]=> string(92)
如果这可以帮助我拥有在两个版本中都可以使用的那个:
->prepare("SELECT COUNT(`p`.`id`) AS `total` FROM `profile` AS `p` GROUP BY YEAR(`p`.`created_account`), MONTH(`p`.`created_account`)");
当我删除该组时,该组有效但未按:/分组,所以我有:
array(9) { [0]=> array(1) { ["month"]=> string(6) "2018-6" } [1]=> array(1) { ["month"]=> string (6) "2018-6" } [2]=> array(1) { ["month"]=> string(6) "2018-7" } [3]=> array(1) { ["month" ]=> string(6) "2018-8" } [4]=> array(1) { ["month"]=> string(6) "2018-8" } [5]=> array(1) { ["month"]=> string(6) "2018-8" } [6]=> array(1) { ["month"]=> string(6) "2018-8" } [7]=> array (1) { ["month"]=> string(6) "2018-8" } [8]=> array(1) { ["month"]=> string(6) "2018-8" } }
那么我应该怎么做才能不重复同月?感谢所有将尝试回答的人:p