;"1 ".each(('123'{~ 'ABC'&i.) each @:{. , }.)"1[ _2 [\ ;: 'A 1.1 2.2 3.3 B 3.4 4.5 5.6 C 6.7 7.8 8.9'
1 1.1 2.2 3.3
2 3.4 4.5 5.6
3 6.7 7.8 8.9
嘿伙计们,所以我已经完成了一个功能来总计列的值,例如" question_asked"选定的日期之间..现在我怎么能总计行,例如图片中的第一行所以(9 + 1 + 4 + 7)= 21?
答案 0 :(得分:0)
我认为这应该有助于查询:
SELECT (SUM(questioned_asked)+SUM(low_confidence)+SUM(no_answer)+SUM(missing_intent)) as total FROM your_table
或强>
SELECT (SUM(questioned_asked + low_confidence + no_answer + missing_intent)) as total FROM your_table
它会像你说的那样( 9 + 1 + 4 + 7 ) = 21
答案 1 :(得分:0)
解决此问题的最佳方法是在查询中使用原始select语句:
public function graph(Request $request)
{
$statistics = DiraStatistics::select(DB::raw('sum(question_asked) as question_asked_sum, sum(low_confidence) as low_confidence_sum, sum(no_answer) as no_answer_sum, sum(missing_intent) as missing_intent_sum, sum(questions_asked + low_confidence + no_answer + missing_intent) as total_sum'))
->whereBetween('date_access', array($request->from, $request->to))
->get();
$question_asked_sum = $statistics->question_asked_sum;
$low_confidence_sum = $statistics->low_confidence_sum;
$no_answer_sum = $statistics->no_answer_sum;
$missing_intent_sum = $statistics->missing_intent_sum;
$total_sum = $statistics->total_sum;
return view('AltHr.Chatbot.graph', compact('question_asked_sum', 'low_confidence_sum', 'no_answer_sum', 'missing_intent_sum', 'total_sum'));
}
另见文档中的raw expressions。
请注意我没有测试过这个。结果可能是Collection而不是Object。喜欢听到结果,所以我可以更新匹配!
答案 2 :(得分:-1)
在DiraStatistics模型类中创建一个方法:
public function getSumnumsAttribute($value)
{
return $this->question_asked + $this->low_confidence + $this->no_answer + $this->missing_intent;
}
现在,您的模型会为您提供$ row-> sumnums的总和。
或汇总的$ num_sum = $ statistics->总和(' sumnums');