sql查找某一字段相同的所有数据

例如表中有三个字段 id name age
1 陈 15
2 张 15
3 李 14
4 王 14

找出所有age相同的数据的sql语句该怎么写?

1、在我们的电脑上打开数据库,这里新建一张含有重复数据的user表做示例。

2、我们输入“select * from user where name in (select name from user group by name having count(name) > 1) ”sql语句,点击运行可以看到查询出了数据库中user表的重复数据。

3、通过“delete from user where   name in (select name from user group by name  having count(name) > 1) ”sql语句删除姓名重复的数据。

4、通过“select distinct name from user”sql语句来去掉重复数据,这里去掉了张三的重复数据。

5、通过“select distinct class from user”sql语句来去掉班级相同的重复数据。

6、也可以通过“select distinct name,class from user”来去掉两个字段的重复数据。

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-07-31

  使用sql模糊查询语句就能够实现;模糊语句的查询模糊条件对应的对象字段是不分前后模糊的,只要内容中有这个字符都能够模糊查询出来。

  sql模糊语法:select * from 表名 where 字段名 like ‘%字符条件%’,而且模糊查询可以使用and和or来关联多个条件查询;

  实际操作如下:

 

  1、在user_user表中,以Dname为查询条件,模糊查询所有有“管”字的数据。如图所示:语法:select * from user_user where Dname like '%管%'

  2、模糊查询可以实现多个字段模糊查询,在查询条件使用and和or来关联查询。and和or的区别:and的意思是“是”,or的意思是“或者”。

  ①、使用and多个模糊条件查询。使用Dname和Dadd两个字段来查询。查询条件中给的字符必须两个条件都成立的时候才能够出来;

  语法:select * from user_user where Dname like '%管%' and Dadd like'%贵%'

  ②、使用or多个模糊条件查询。使用Dname和Dadd两个字段来查询。查询条件中给的字符其中一个条件成立即可。

  语法:select * from user_user where Dname like '%管%' or Dadd like'%贵%'

第2个回答  2015-10-17

1、可以使用WHERE子句进行查询。

2、如要查询t1表中name字段为张三的所有数据,可以使用以下语句。

3、语句为:

SELECT * FROM t1 WHERE name = '张三'

第3个回答  2011-06-16
你的问题看不懂。

1。查询某个age=15相同的数据
select * from table where age = 15

2。查询各个age相同的数据
select * from table order by age
第4个回答  2011-06-16
select *from 此表 as A join (select count(age) from 此表 group by age) B on A.age=B.age 这样按相同年龄记录分类显示出来