我现在想根据title值中出现2次以上的oid和title查询出来。
结果为
userid title oid
1 vip保过版 spSP1385780556RN533,SP1387183506RN165,SP1389331511RN950
前面的sql语句为
select userid,group_concat( title),group_concat(distinct oid) from `djs_shops_products` group by userid;
...全文
5767打赏收藏
sql中如何判断一个id下出现两次以上某字段的值
我现在想根据title值中出现2次以上的oid和title查询出来。 结果为 userid title oid 1 vip保过版 spSP1385780556RN533,SP1387183506RN165,SP1389331511RN950 前面的sql语句为 select userid,group_concat( title),group_concat(distinct oid) from `djs_shops_products` group by userid;
版主
select userid,group_concat(distinct title),group_concat(distinct oid) from `djs_shops_products` a where 2>=(select count(*) from `djs_shops_products` where a.title=title and a.userid=userid)group by userid;
我有这么修改了一下,但是结果导致他的>=的条件判断好像失败了
版主 我用你给我提供的语句select userid,title,group_concat(distinct oid) from `djs_shops_products` a where 2>=(select count(*) from `djs_shops_products` where a.title=title) group by(userid)
查询结果
并不是我想要的啊