Skip to content

Instantly share code, notes, and snippets.

@nsanden
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsanden/6a74fbad19282cffd93c to your computer and use it in GitHub Desktop.
Save nsanden/6a74fbad19282cffd93c to your computer and use it in GitHub Desktop.
$transes = (new \yii\db\Query())
->select('DATE_FORMAT(FROM_UNIXTIME(`created`), "%M %Y") as `dates`, SUM(amount) AS amount, SUM(fee) AS fee, SUM(net) AS net, SUM(IF(`amount`< 0, `amount`, 0 )) AS pay_out')
->from('tbl_transaction_newest')
->groupBy('`dates`')
->limit(1000)
->orderBy('created')
->all();
SQLSTATE[42000]: 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 `pay_out` FROM `tbl_transaction_newest` GROUP BY `dates` ORDER BY `created` L' at line 1
The SQL being executed was: SELECT DATE_FORMAT(FROM_UNIXTIME(`created`), "%M %Y") as `dates`, SUM(amount) AS amount, SUM(fee) AS fee, SUM(net) AS net, SUM(IF(`amount`< `0`, `amount`, `0 ))` AS `pay_out` FROM `tbl_transaction_newest` GROUP BY `dates` ORDER BY `created` LIMIT 1000
Error Info: Array
(
[0] => 42000
[1] => 1064
[2] => 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 `pay_out` FROM `tbl_transaction_newest` GROUP BY `dates` ORDER BY `created` L' at line 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment