【问题标题】:How to sum value column in query builder phalcon如何在查询生成器 phalcon 中对值列求和
【发布时间】:2020-10-12 03:18:19
【问题描述】:

我想在框架phalcon 中对查询生成器中的值求和,这是我的代码生成器

$builder = new Builder();
$builder
  ->columns([
    "TABLE1.ID_TABLE1",
    "count(distinct TABLE2.SKPD_SUB1_ID) as RESULT_1",
    "count(distinct TABLE3.SKPD_SUB1_ID) as RESULT_2",
    "count(distinct TABLE_4.SKPD_SUB1_ID) as RESULT_3",
    //in there i want to add RESULT_1 + RESUL_2 + RESULT_3 
  ])
  ->from("TABLE1")
  ->leftjoin("TABLE2", "TABLE2.SKPD_SUB1_ID=TABLE1.SKPD_SUB1_ID")
  ->leftjoin("TABLE3", "TABLE3.SKPD_SUB1_ID=TABLE1.SKPD_SUB1_ID")
  ->leftjoin("TABLE_4", "TABLE_4.SKPD_SUB1_ID=TABLE1.SKPD_SUB1_ID")
  ->where("TABLE1.SKPD_ID='$skpd_id'");

$result = $builder - > getQuery() - > execute();

【问题讨论】:

    标签: php mysql sql phalcon phalcon-orm


    【解决方案1】:

    你可以试试这样的:

    select sum(a.cnt) 
      from (
              select count(...) as cnt 
              from ... 
              group by ...
           ) as a
    

    【讨论】:

      猜你喜欢
      • 2016-10-03
      • 2021-11-13
      • 2015-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-15
      • 2020-04-23
      • 2019-09-12
      相关资源
      最近更新 更多