select id,name,select count(*) from table1 where table1.infor regexp 'g'+table2.id+'(g|$)' as count from table2
如统计table1的infor字段里有g24但没有g240(这24是table2.id自动赋予的),但现在的语句不能区分,请大神赐教!
查了一下mysql的文档,原来很简单,mysql有个专门的字符串连接的函数concat,(汗,是自己一直没好好学习的结果。)现在正确的查询语句如下:
$sql='select *,(SELECT count(*) FROM yy_members where groupsinfor REGEXP concat("G",yy_mygroup.groupid,"(G|$)") and userid=1) as count from yy_mygroup where userid=1';
不知道有没有更好的方案呢?