[英]laravel query builder how to sum multiple specific columns
hello I have a candidate total scores table 你好,我有一个候选人总成绩表
sample 样品
I want to add the casual_wear and evening_gown where candidate ID =1 我想在候选人ID = 1的地方添加便装和晚礼服
what I got so far 我到目前为止所得到的
DB::table('total_score')
->select(DB::raw('SUM(casual_wear) as total_scores'))
->where('candidate_number', '=' , '1')
->orderBy('total_scores', 'desc')
->get();
i don't know how to add to different columns pls help, tnx in advance 我不知道如何添加到不同的列请帮助,提前tnx
I want to add the casual_wear and evening_gown where candidate ID =1
我想在候选人ID = 1的地方添加便装和晚礼服
Then why can't you just perform addition on those two columns like 那为什么不能只对这两列进行加法运算
select casual_wear + evening_gown as some_alias
from total_score
where candidate_ID =1;
(OR) probably you meant to do a SUM()
GROUP BY candidate_ID
like (OR)可能您想做一个
SUM()
GROUP BY candidate_ID
select SUM(casual_wear) as total_scores,
SUM(evening_gown) as total_scores1
from total_score
GROUP BY candidate_ID
order By SUM(casual_wear) desc;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.