我試着去找出該MySQL查詢語句轉換成笨的Active Record風格查詢語句用SUM()
SELECT
SUM(invite.friendID = $mID AND invite.decidedwhen = '0000-00-00 00:00:00' AND evnt.ends >= '$event_ts' and invite.isactive = 0 and evnt.isactive = 0) AS invites_undecided,
SUM(invite.friendID = $mID AND invite.decidedwhen != '0000-00-00 00:00:00' AND invite.yes = 1 AND evnt.ends >= '$event_ts' and invite.isactive = 0) and evnt.isactive = 0 AS invites_yes,
SUM(invite.friendID = $mID AND invite.decidedwhen != '0000-00-00 00:00:00' AND invite.no = 1 AND evnt.ends >= '$event_ts' and invite.isactive = 0 and evnt.isactive = 0) AS invites_no,
SUM(invite.friendID = $mID AND invite.decidedwhen != '0000-00-00 00:00:00' AND invite.maybe = 1 AND evnt.ends >= '$event_ts' and invite.isactive = 0 and evnt.isactive = 0) AS invites_maybe
FROM user_event_invite AS invite
JOIN user_event AS evnt ON evnt.eID = invite.eID
轉換這個MySQL查詢使用Codeigniters活動記錄格式的東西的最佳方式。 EG
$this->db->select()
->from('user_event')
->... something?
標準mysql語句工作得很好。但是爲了堅持統一我想使用活動記錄的一切。任何這樣做? (因爲我沒有測試它比回答的評論,但它仍可能幫助)我找不到SUM()
$這個 - > DB-> select_sum(..)? – Mate
我搜索了上下類似的東西,找不到它。然而,我仍然處於一個障礙之中,因爲它沒有出現(基於現在的指導我發現它),我可以多次使用'select_sum',並且如果可以的話?我如何在每個SUM()的條件中考慮因素,就像我上面所說的那樣? – chris