Answer the question
In order to leave comments, you need to log in
Why does Yii2 handle MySQL queries incorrectly?
Hello!
I wanted to get the number of users by status
, so there is a user table and the status fields are 1 or 0
if I write a request in PhpMyAdmin, then everything works fine ....
SELECT SUM(IF(status = "1",1,0)) AS active,SUM(IF(status = "0",1,0)) AS inactive FROM `user`
(new \yii\db\Query())->from('user')->select('SUM(IF(status = "1",1,0)) AS active, SUM(IF(status = "0",1,0)) AS inactive')->all()
Syntax error or access violation: 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 'AS `status_active` FROM `user`' at line 1
The SQL being executed was: SELECT SUM(IF(status = "1", `1`, `0))` AS `status_active` FROM `user`
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question