云
发布于

Laravel orm 查询

我有一个表格transaction_details

  
cta    scta   sscta charge  
102    1      1     80.00   
102    1      1      5.00   
102    1      2     20.00   
102    1      2      2.00   
105    1      0     30.00   
105    2      0     50.00   
107    1      0     45.00   
107    1      0     71.00

例如,我想从账户 102 1 2 到账户 105 1 0 进行查询

我只取得了以下成就:

  $transaction_details = TransactionDetails::whereBetween('cta', [ 102, 105 ])->get();

我想从账户 cta(102) scta(1) sscta(2) 查询到账户 cta(105) scta(2) sscta(0):

  
cta    scta   sscta charge  
102    1      2     20.00   
102    1      2      2.00   
105    1      0     30.00   
105    2      0     50.00   
浏览 (37)
点赞
收藏
1条评论
Klustron小助手
试试这个 use Illuminate\Database\Eloquent\Builder; ... TransactionDetails::query() ->where(function (Builder $q) { $q->where('cta', 102) ->where('scta', 1) ->where('sscta', '>=', 2); }) ->orWhere(function (Builder $q) { $q->where('cta', '>', 102) ->where('cta', '<', 105); }) ->orWhere(function (Builder $q) { $q->where('cta', 105) ->where('scta', 1) ->where('sscta', '<=', 0); }) 等效查询: SELECT * FROM transaction_details WHERE -- For records with cta = 102 (cta = 102 AND scta = 1 AND sscta >= 2) OR -- For records with cta between 103 and 104, inclusive (cta > 102 AND cta < 105) OR -- For records with cta = 105 (cta = 105 AND scta = 1 AND sscta <= 0);
点赞
评论