laravel 查询生成器如何对多个特定列求和
laravel query builder how to sum multiple specific columns
你好我有一个考生总分table
样本
我想添加 casual_wear 和 evening_gown,其中候选人 ID =1
到目前为止我得到了什么
DB::table('total_score')
->select(DB::raw('SUM(casual_wear) as total_scores'))
->where('candidate_number', '=' , '1')
->orderBy('total_scores', 'desc')
->get();
我不知道如何添加到不同的列请帮忙,提前tnx
I want to add the casual_wear and evening_gown where candidate ID =1
那你为什么不能像
那样对这两列进行加法呢?
select casual_wear + evening_gown as some_alias
from total_score
where candidate_ID =1;
(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;
你好我有一个考生总分table
样本
我想添加 casual_wear 和 evening_gown,其中候选人 ID =1
到目前为止我得到了什么
DB::table('total_score')
->select(DB::raw('SUM(casual_wear) as total_scores'))
->where('candidate_number', '=' , '1')
->orderBy('total_scores', 'desc')
->get();
我不知道如何添加到不同的列请帮忙,提前tnx
I want to add the casual_wear and evening_gown where candidate ID =1
那你为什么不能像
那样对这两列进行加法呢?select casual_wear + evening_gown as some_alias
from total_score
where candidate_ID =1;
(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;