2026, 새로운 도약을 시작합니다.

쿼리문 합계 질문드립니다. 채택완료

Copy


$sub_lists = array();

$sub_sqls = array(

    "select count(*) cnt from {$write_table_a} where wr_53='{$row['wr_53']}' and NOT wr_7 IN ('9') AND REPLACE(wr_45, ',', '') > 0 and wr_29 between '{$stx1}' and '{$stx2}' group by mb_id",

    "select count(*) cnt from {$write_table_b} where wr_53='{$row['wr_53']}' and NOT wr_7 IN ('9') AND REPLACE(wr_45, ',', '') > 0 and wr_29 between '{$stx1}' and '{$stx2}' group by mb_id",

    "select count(*) cnt from {$write_table_a} where wr_53='{$row['wr_53']}' and NOT wr_7 IN ('9') AND REPLACE(wr_45, ',', '') > 0 AND REPLACE(wr_45, ',', '')  0 AND REPLACE(wr_45, ',', '')  1540000 AND REPLACE(wr_45, ',', '')  1540000 AND REPLACE(wr_45, ',', '')  3600000 and wr_29 between '{$stx1}' and '{$stx2}' group by mb_id",

    "select count(*) cnt from {$write_table_b} where wr_53='{$row['wr_53']}' and NOT wr_7 IN ('9') AND REPLACE(wr_45, ',', '') > 3600000 and wr_29 between '{$stx1}' and '{$stx2}' group by mb_id"

  );

foreach ($sub_sqls as $sub_sql) {

    $sub_list = array();

    $sub_result = sql_query($sub_sql, true);

    while ($sub_row = sql_fetch_array($sub_result)) {

        $sub_list[] = $sub_row;

    }

    $sub_lists[] = $sub_list;

}

$set_count_all        = count(array_merge($sub_lists[0], $sub_lists[1]));

$set_count_under    = count(array_merge($sub_lists[2], $sub_lists[3]));

$set_count_154        = count(array_merge($sub_lists[4], $sub_lists[5]));

$set_count_360        = count(array_merge($sub_lists[6], $sub_lists[7]));

단순하게

$set_count_all 의 카운트는

$set_count_under+ $set_count_154+$set_count_360        
의 합계가 나와야 하는데
 $set_count_all의 카운트 수가 더 적습니다.

왜 카운트 수가 맞질 않을까요?

답변 2개

그룹핑은 통계할때만 필요해요

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

아이디별로. 뭔가 하는 것 같지 않은데

첫째, 둘째 query 에서

group by mb_id

를 넣으신 목적이 있을까요?

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고