我的表名为abc,列为
id table_row_name a b c
1 user 1 1 Null
2 user Null Null 1
如何通过如下所示的查询合并到一条记录中,如何用laravel进行记录
table_row_name a b c
user 1 1 1
答案 0 :(得分:0)
您可以在下面的查询中尝试
select table_row_name, max(a) as a, max(b) as b, max(c) as c
from tablename
group by table_row_name
答案 1 :(得分:0)
您可以通过以下查询简单地实现该目标:
\DB::table('abc')
->select([
'table_row_name',
\DB::raw('MAX(a) as a'),
\DB::raw('MAX(b) as b'),
\DB::raw('MAX(c) as c')
])
->groupBy('table_row_name')
->get();