如何使用yii
createCommand 编写以下选择查询。这在phpmyadmin中运行得很完美吗?
SELECT total_units, nav, total_units * nav as total
FROM user_nav_stats
where total_units !=0
答案 0 :(得分:1)
如果您不想以SQL身份运行它,那么
$connection->createCommand('SELECT total_units, nav, total_units * nav as total FROM user_nav_stats where total_units !=0')->queryAll();
但我会使用Querybuilder。它是这样的。 More can be found here
$rows = (new \yii\db\Query())
->select(['total_units', 'nav', 'total_units * nav as total'])
->from('user_nav_stats')
->where(['!=','total_units',0])
->all();