2016-07-05 73 views
1

我想加入一個表本身,但不斷收到錯誤。這是我目前的代碼。我也嘗試過Raw語句。目前不知道該走哪個方向。雄辯 - 連接表本身

我的代碼:

$Calle = db('VoipBill') 
        ->table('billing') 
        ->join('billing', 'billing.srcnum', '=', 'billing.dstnum') 
        ->where('acct_name', '100080_company') 
        ->where('srcnum', $call->srcnum) 
        ->whereBetween('calldate', [$set_time_lower, $set_time_upper]) 
        ->get(); 

這是錯誤:

SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'billing' (SQL: select * from billing inner join billing on billing . srcnum = billing . dstnum where acct_name = 100080_company and srcnum = +27******** and calldate between 2016-05-02 09:19:27 and 2016-05-02 09:19:37)

回答

3

你有別名的表。試試看吧:

$Calle = db('VoipBill') 
     ->table('billing as bsrc') 
     ->join('billing as bdst', 'bsrc.srcnum', '=', 'bdst.dstnum') 
     ->where('bsrc.acct_name', '100080_company') 
     ->where('bsrc.srcnum', $call->srcnum) 
     ->whereBetween('bsrc.calldate', [$set_time_lower, $set_time_upper]) 
     ->get();