ちょっと、私は結合されたテーブルのカラムrt.x_typeに関係のないすべてのID(これはACTUAL_ENTRIESのエイリアスです)を数えたいと思います。私はzendフレームワークを使用します。ここに私のORMクエリ全体があります。MySQLのカウントIDの値が異なるカラムの値
$columns = array(
'EV.id as EVENT_ID',
'EV.name as EVENT_NAME',
'DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(EV.start_time), "UTC", LO.time_zone), "%m/%e/%Y %a %r") as EVENT_START_DATE',
'LO.time_zone as TIME_ZONE',
'coalesce(EV.expected_entry, "") as EXPECTED_ENTRIES',
$db->quoteInto('count(if(RT.x_type NOT IN ("CREDIT","EXTERNAL"),EN.id,0)) AS ACTUAL_ENTRIES'),
$db->quoteInto('sum(IF(EN.type != ?, 1, 0)) AS ACTUAL_ATHLETES', Entry::ENTRY_TYPE_TEAM),
$db->quoteInto('sum(IF(EN.type = ?, 1, 0)) AS ACTUAL_TEAMS', Entry::ENTRY_TYPE_TEAM),
'coalesce(T.name,"") as TIMER_NAME',
'coalesce(T.phone, "") as TIMER_PHONE',
'coalesce(T.sales_region, "") as SALES_REGION'
);
$rows = $this->_readonlydb->select()
->from(array('EV' => 'event'),'')
->join(array('LO' => 'location'),'EV.location_id = LO.id','')
->joinLeft(array('RT' => 'reg_transaction'),
"RT.event_id = EV.id AND
(RT.is_test = 0 OR RT.is_test IS NULL) AND
RT.x_response_code = " . RegTransaction::RESPONSE_CODE_SUCCESS . "", '')
->joinLeft(array('EN' => 'entry'), 'EN.trans_id = RT.id', '')
->joinLeft(array('T' => 'organization'), 'T.id = EV.timer_id', '')
->where('EV.is_test_event = ?', 0)
->where("EN.status NOT IN (?)", array(Entry::ENTRY_STATUS_WITHDRAWN, Entry::ENTRY_STATUS_NEW))
->where('YEARWEEK(FROM_UNIXTIME(EV.start_time), 3) = ?', date("YW"))
->group('EV.id')
->columns($columns)
->query()
->fetchAll()
;
重要な部分は、この作業ではない
$db->quoteInto('count(if(RT.x_type NOT IN ("CREDIT","EXTERNAL"),EN.id,0)) AS ACTUAL_ENTRIES'),
です。誰かが私に何かを提案することができます
SQLクエリを作成しましたか?もしそうなら、それをお願いします。 –