gpt4 book ai didi

php - 在 Eloquent ORM laravel 中查询列行总和的最佳结果?

转载 作者:行者123 更新时间:2023-11-28 23:17:47 25 4
gpt4 key购买 nike

我有一张这样的 table enter image description here

现在我首先查询相同的 temperaturzeit 的结果,例如

(select * from table where temperatur= array..  AND zeit=array...). 

现在例如我得到这样的结果:

enter image description here

一个温度和 zeit= 85,30,另一个是 85,45..

现在根据(aussehen,farbe,deformation,geruch,texture)的列求和求最好的结果。

例如,匹配列的行的最终总和是(14),另一个匹配是(17)我想得到最好的结果,即 14..

我如何在 Laravel orm 中做到这一点?

对于整个查询,我使用了这个

orderBy( DB::raw('(aussehen) + (farbe)+(deformation)+(geruch)+(texture)'))->limit(1)->get();

但知道我想比较总和的结果..

我希望我已经正确解释了我的问题..

最佳答案

试试这个:

$result = DB::('table')
->select(DB::raw('*, (aussehen) + (farbe)+(deformation)+(geruch)+(texture) as sum'))
->where('temperature', '=', $temp) //variable passed to function
->where('zeit', '=', $zeit) // variable passed to function
->orderBy('sum', 'asc')
->first();

关于php - 在 Eloquent ORM laravel 中查询列行总和的最佳结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43096097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com