sql中如何判断一个id下出现两次以上某字段的值

legendnan 2014-02-26 11:03:58

我现在想根据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;
...全文
576 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
legendnan 2014-02-26
  • 打赏
  • 举报
回复
引用 1 楼 wwwwb 的回复:
select * from tt a where 2>=(select count(*) from tt where a.title=title)

版主
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;
我有这么修改了一下,但是结果导致他的>=的条件判断好像失败了
legendnan 2014-02-26
  • 打赏
  • 举报
回复
引用 3 楼 JenMinZhang 的回复:
句法解释: char_length( title) #获得字符串长度 replace( title, “vip保过版” ) #将字符串中的A替换为空 char_length( title) – char_length( replace( title, “vip保过版”, ” ) ) #计算得到差就是被替换的字符串的个数 select char_length( title) – char_length( replace( title, “vip保过版”, ” ) ) from tt a where 1 group by userid 但每次只能查询一个....
我想要所有的。不是单一的
legendnan 2014-02-26
  • 打赏
  • 举报
回复
引用 1 楼 wwwwb 的回复:
select * from tt a where 2>=(select count(*) from tt where a.title=title)

版主 我用你给我提供的语句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)
查询结果
并不是我想要的啊
知道就是你 2014-02-26
  • 打赏
  • 举报
回复
句法解释: char_length( title) #获得字符串长度 replace( title, “vip保过版” ) #将字符串中的A替换为空 char_length( title) – char_length( replace( title, “vip保过版”, ” ) ) #计算得到差就是被替换的字符串的个数 select char_length( title) – char_length( replace( title, “vip保过版”, ” ) ) from tt a where 1 group by userid 但每次只能查询一个....
WWWWA 2014-02-26
  • 打赏
  • 举报
回复
select * from tt a where 2>=(select count(*) from tt where a.title=title and a.userid=userid )
wwwwb 2014-02-26
  • 打赏
  • 举报
回复
select * from tt a where 2>=(select count(*) from tt where a.title=title)
WWWWA 2014-02-26
  • 打赏
  • 举报
回复
select * from tt a where 2>=(select count(*) from tt where a.title=title) 直接运行,不加入group_concat,结果是什么

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧