我有主题表中的记录列表,然后我想添加到yii2绑定方法的group_concat。
Table Structure
===============
id, sname
1 english
2 maths
$datas = Subjects::find()->select("Group_concat(sname)")->where('FIND_IN_SET(id,"1,2")')->one();
return $datas->sname;
但我必须只获得单一值。我想结果是"英语,数学"但我的结果是"英语"仅?
答案 0 :(得分:0)
您应该使用别名为结果指定名称..例如g_sname
$datas = Subjects::find()->select("Group_concat(sname) as g_sname")
->where('FIND_IN_SET(id,"1,2")')
->one();
return $datas->g_sname;
你也可以尝试使用column()
$concatName = Subjects::find()->select("Group_concat(sname) as g_sname")
->where('FIND_IN_SET(id,"1,2")')->column()
->one();
return $concatName ;