【问题标题】:Yii select multiplication of two columns in yii using createCommandYii 使用 createCommand 在 yii 中选择两列的乘法
【发布时间】:2016-09-06 13:51:52
【问题描述】:

如何使用yii createCommand 编写以下选择查询。这在 phpmyadmin 中运行完美?

SELECT total_units, nav, total_units * nav as total 
FROM user_nav_stats 
where total_units !=0

【问题讨论】:

    标签: select yii


    【解决方案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();
    

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-02
      • 2014-08-05
      • 1970-01-01
      相关资源
      最近更新 更多