您的位置:首页 > 数据库

wm_concat 函数在开发中的应用 (一对多查询数据库实现)

2017-03-29 17:46 225 查看

个人宣言

争取做一个懂点数据库且有趣的程序员。



wm_concat 函数在开发中的应用 (一对多查询数据库实现)

wm_concat 函数可以把列值中间用 “,”号隔开,并且在一行显示。

sql 语句,例如:

select wm_concat(t.icityid) as icityids   from tb_lend_filter_product_city t




wm_concat 和 group by 配合使用 (通过表关联查出一对多的关系)

实例:(查出产品内容,以及对应显示的城市cityid)

SELECT t0.*,t2.* FROM TB_LEND_FILTER_PRODUCT t0

LEFT JOIN (select wm_concat(t.icityid) as icityids ,t.iproductid

from tb_lend_filter_product_city t  group by t.iproductid) t2 ON  t2.iproductid=t0.id


前端得到 icityids 遍历出来

var  icityid;

if(bindData.icityids   !=undefined&&bindData.icityids   !='')

{

icityid= bindData.icityids.split(",");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据库 java 函数
相关文章推荐