mysql group_concat自增主键问题

在进行分组时,有时候需要将某一字段的值以逗号或其它符号拼接在一起,可以使用group_concat函数来完成,如果要拼的字段是字符型的,很好办,用group_concat(字段名 separator ",")就行.
今天在测试程序时,发现有问题,后来发现就是group_concat函数的问题,拼接的字段是主键ID,我设为自动增长,我使用 group_concat(oct(doId) separator ",")发现拼接的主键不对劲,如果不使用oct()函数,对于要拼接的字段是数字型的这种情况,产生的结果就会是一个BLOB数据,因此要使用函数来处 理一下,后来我查了查MYSQL手册,发现oct()函数是返回一个8进制的数,原因找到了就好解决了,于是就再找啊找啊,找到了conv()函数,再转 换成10进制的数字就OK了,返回的结果正如我意,group_concat(conv(oct(doId),8,10) separator ",") 和
group_concat(conv(conv(doId,10,8),8,10) separator ',') 产生的效果是一样的

 

转载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
select a.*, b.name activityName, c.name productName, c.member_max memberMax, d.status as complete, group_concat(if(e.face_value is null, "", e.face_value) separator "\n") as rewardAmount, group_concat(if(e.coupon_code is null, "", e.coupon_code ) separator "\n") as couponCode , group_concat(if(e.coupon_id is null, "", e.coupon_id) separator "\n") as caId from marketing_group_tool_group_member a left join marketing_group_tool_group_info d on a.group_id = d.id left join marketing_group_tool_activity b on a.activity_id = b.activity_id left join marketing_group_tool_product_base c on a.product_id = c.product_id left join marketing_group_tool_send_coupon_record e on (a.group_id = e.group_id and a.card_no = e.card_no) left join wx_recommend_organization organization on b.organization_id = organization.id where ((organization.tree_id between 2002000000000000 and 2002999999999999) or (organization.tree_id between 1000000000000000 and 1999999999999999) or (organization.tree_id between 2000000000000000 and 2999999999999999) or (organization.tree_id between 3000000000000000 and 3999999999999999) or (organization.tree_id between 4000000000000000 and 4999999999999999) or (organization.tree_id between 6000000000000000 and 6999999999999999) or (organization.tree_id between 5000000000000000 and 5999999999999999) or (organization.tree_id between 10000000000000000 and 10999999999999999) or (organization.tree_id between 8000000000000000 and 8999999999999999) or (organization.tree_id between 9000000000000000 and 9999999999999999) or (organization.tree_id between 11000000000000000 and 11999999999999999) or (organization.tree_id between 12000000000000000 and 12999999999999999) or (organization.tree_id between 13000000000000000 and 13999999999999999) or (organization.tree_id between 14000000000000000 and 14999999999999999) or (organization.tree_id between 15000000000000000 and 15999999999999999) or (organization.tree_id between 16000000000000000 and 16999999999999999) or (organization.tree_id between 17000000000000000 and 17999999999999999) ) and 1 = 1 group by a.id, a.activity_id , a.group_id , a.product_id , a.activity_referral_code, a.product_referral_code , a.openid , a.unionid , a.nickname , a.head_img , a.mobile , a.is_sub_buy , a.is_sub_progress , a.is_sub_success , a.sort , a.card_no , a.create_time , a.is_received_notice , a.is_received_progress , a.is_received_success , b.name, c.name, c.member_max , d.status order by a.id desc limit 0,20;
最新发布
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值