0

我想在框架的查询生成器中求和值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();
4

1 回答 1

0

你可以尝试这样的事情:

select sum(a.cnt) 
  from (
          select count(...) as cnt 
          from ... 
          group by ...
       ) as a
于 2020-11-09T15:51:57.400 回答