gpt4 book ai didi

laravel - Group_concat - 查询生成器

转载 作者:行者123 更新时间:2023-12-02 17:02:57 27 4
gpt4 key购买 nike

这是我的 SQL 操作:

select `id_ifc_espaces`,GROUP_CONCAT(DISTINCT `nom_espace`) as   nom_espace ,GROUP_CONCAT(DISTINCT `fonction_espace`) as fonction_espace, GROUP_CONCAT(DISTINCT `id_ouvrage_slab_wall`) as id_ouvrage_slab_wall , GROUP_CONCAT(DISTINCT `type_limit`) as type_limit,GROUP_CONCAT(DISTINCT `type_ouvr`) as type_ouvr from `relespouv` group by`id_ifc_espaces` 

这是我尝试过的查询生成器:

$relations = DB::table('relespouv')
->select('id_ifc_espaces')
->group_by('id_ifc_espaces')
->where('id_mn','=',$idmn)
->get(array(DB::raw('GROUP_CONCAT(DISTINCT nom_espace) as nom_espace,
GROUP_CONCAT(DISTINCT fonction_espace) AS fonction_espace,
GROUP_CONCAT(DISTINCT id_ouvrage_slab_wall) AS id_ouvrage_slab_wall,
GROUP_CONCAT(DISTINCT type_limit) AS type_limit,
GROUP_CONCAT(DISTINCT type_ouvr) AS type_ouvr ')));

当我尝试使用例如 nom_espace 时:

 $relespouv[$allelement['Relation']][12]=$relation->nom_espace;

我收到错误:

Undefined property: stdClass::$nom_espace

谁能帮帮我吗?

最佳答案

你应该搬家

array(DB::raw('GROUP_CONCAT(DISTINCT nom_espace) as   nom_espace,
GROUP_CONCAT(DISTINCT fonction_espace) AS fonction_espace,
GROUP_CONCAT(DISTINCT id_ouvrage_slab_wall) AS id_ouvrage_slab_wall,
GROUP_CONCAT(DISTINCT type_limit) AS type_limit,
GROUP_CONCAT(DISTINCT type_ouvr) AS type_ouvr ')
)

get()select() 像这样

$relations = DB::table('relespouv')
->select(array(
'id_ifc_espaces'
DB::raw('GROUP_CONCAT(DISTINCT nom_espace) as nom_espace,
GROUP_CONCAT(DISTINCT fonction_espace) AS fonction_espace,
GROUP_CONCAT(DISTINCT id_ouvrage_slab_wall) AS id_ouvrage_slab_wall,
GROUP_CONCAT(DISTINCT type_limit) AS type_limit,
GROUP_CONCAT(DISTINCT type_ouvr) AS type_ouvr ')
))
->group_by('id_ifc_espaces')
->where('id_mn','=',$idmn)
->get();

关于laravel - Group_concat - 查询生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29434011/

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