表article,
id title content
1 dailybookstore1 xxxxxxxxxxxxxx
2 dailybookstore2 xxxxxxxxxxxxxx
3 dailybookstore3 xxxxxxxxxxxxxx
4 dailyappstore1 xxxxxxxxxxxxxx
5 dailyappstore2 xxxxxxxxxxxxxx
6 result xxxxxxxxxxxxxx
语句要求,排除掉表中有类似title的结果,最后只能查出id为6的结果,不知道能不能实现,如果能的话,怎么写,谢谢
请描述清楚问题,
排除表中类似title的结果(排除daily): select * from article where title not like 'daily%';
我大致理解了一下,任意两个title字段的字符串只要存在相同字符段,那就是类似title。要实现这种筛选,建议写一个正则表达式进行筛选,一般的like语句做不到。
类似的话就是要使用到关键字 like,使用实例:like '...%...'
select * from article where title not like 'daily%';
意思是排除title有重复得数据 可以先group by 查出相同title得id 然后 not in
语句:select * from article where id not in (select id from article group by title having count(*)>1);
如果不要title的内容,那就选择id和content不就好了,select id,content from article where id=6
select ,count() as count from article group by left(title,5) having count=1; 这样或许可以稍微有点用处
看了你这个问题,提供给你解决此类问题的思路
1.既然你需要剔除包含以上title的列,需要明确dailybookstore1 ,dailyappstore1这两种字段值,是否包含dailyappstore999,dailyappstore999这样的结果,如果不包含,
可以这样select * from table where title not like 'dailybookstore%' and title not like 'dailyappstore%';