dounangqie4819 2014-02-14 11:32
浏览 178
已采纳

MySQL获取行,这些行不包含特定的字符串/单词

I want a MySQL query to return rows which don't have the only input string/phrase in it.

Example: I have table with the column name like

Sno  | sname
---------------
1    | AAA
2    | SSS
3    | Group Post
4    | Group Post, Test Run
5    | Group Post, Group Post
6    | Group Post, Group Post, My test Run

In the above table I want to eliminate the rows which have "Group Post" only in them. That means how many times Group Post exist in the row and there are no other phrases or words in them, then we can eliminate it.

So I want a query which will return

Sno  | sname
---------------
1    | AAA
2    | SSS
4    | Group Post, Test Run
6    | Group Post, Group Post, My test Run

In these rows some of them have Group Post in them. But along with the that we have other phrases in them.

Thanks in Advance.

  • 写回答

4条回答 默认 最新

  • douren6035 2014-02-14 11:50
    关注

    You need REPLACE function to filter the data.

    Try this:

    select * from my_table
     where length( replace( replace( sname, 'Group Post', '' ), ', ', '' ) ) > 0
    

    Refer to:
    MySQL: REPLACE(str,from_str,to_str) Function

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况