2015-04-03 88 views
3

这是我的SQL操作:GROUP_CONCAT - 查询生成器

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

任何人都可以帮助我吗?

回答

3

您应该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 ') 
) 

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(); 
+0

感谢这个解决它 – 2015-04-03 14:33:54

+0

@YOSRABENSALAH乐意帮助,你能接受我的答案,如果它帮助:) – 2015-04-03 14:34:59