1
次のクエリを参照してください。codeigniterアクティブレコードへのSQLクエリの変換
CodeIgnitor Active Recordsに変換したいです。
SQLクエリ:
Select MobNo,Caller,Sum(Tot_In_Call) as Tot_In_Call,Called,Sum(Tot_Out_Call) as Tot_Out_Call
From (
SELECT CTE.Caller as MobNo,Incall.Caller,Incall.Tot_In_Call, Null as Called,0 as Tot_Out_Call
FROM Call_Details CTE
Left Join (
Select Count(Called) as Tot_In_Call,Caller,Called
from call_details
Group By Caller,Called
) InCall on (Cte.caller = InCall.Called)
Where InCall.Called in($call_array)
Group BY CTE.Caller,Incall.Caller,Incall.Tot_In_Call
Union All
SELECT CTE.Caller as MobNo,Null as Caller,Null as Tot_In_Call, OutCall.Called,OutCall.Tot_Out_Call
FROM Call_Details CTE
Left Join (
Select Count(Called) as Tot_Out_Call,caller,Called
from call_details
group by caller,called
) OutCall on (CTE.caller = OutCall.caller And cte.called = OutCall.called)
Where CTE.Caller in($call_array)
Group BY CTE.Caller,OutCall.Called,OutCall.Tot_Out_Call
) As Qry
WHERE Qry.MobNo in($call_array)
Group By Qry.MobNo,Qry.Caller,Qry.Called
order by Qry.MobNo,Qry.Caller,Qry.Called
がどのように私は$this->db->query()
を使用せずにこれを変換することができますか?
は、アクティブなレコードを使用して作ってみました: -
$this->db->select("MobNo,Caller,Sum(Tot_In_Call) as Tot_In_Call,Called,Sum(Tot_Out_Call) as Tot_Out_Call");
$this->db->from("SELECT CTE.Caller as MobNo,Incall.Caller,Incall.Tot_In_Call, Null as Called,0 as Tot_Out_Call
FROM Call_Details CTE
Left Join (
Select Count(Called) as Tot_In_Call,Caller,Called
from call_details
Group By Caller,Called
) InCall on (Cte.caller = InCall.Called)
Where InCall.Called in($call_array)
Group BY CTE.Caller,Incall.Caller,Incall.Tot_In_Call
Union All
SELECT CTE.Caller as MobNo,Null as Caller,Null as Tot_In_Call, OutCall.Called,OutCall.Tot_Out_Call
FROM Call_Details CTE
Left Join (
Select Count(Called) as Tot_Out_Call,caller,Called
from call_details
group by caller,called
) OutCall on (CTE.caller = OutCall.caller And cte.called = OutCall.called)
Where CTE.Caller in($call_array)
Group BY CTE.Caller,OutCall.Called,OutCall.Tot_Out_Call");
$this->db->where_in("MobNo",$call_array);
$this->db->group_by("MobNo,Caller,Called");
$this->db->order_by("MobNo,Caller,Called","ASC");
$this->db->get();
事前にあなたにたくさんありがとうございました。
を参照してください。 – AkshayP
すでに$ this-> db-> query()を使わずに方法を見つけられませんでした。 ... –
なぜ$ this-> db-> query()を使いたくないのですか? ? – AkshayP