Group_concat - 查询生成器
Group_concat - query builder
这是我的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();
这是我的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();