查询某个字段重复的记录
2023-01-10阅读(912)
问:怎么查看数据库表中某个字段的值有哪些重复记录
- 答:查看可用如下方法:
1、创建测试表,插入数据:
create table product
(id int,
name varchar(10),
totol int)
insert into product values (1,'香蕉',100)
insert into product values (2,'橘子',67)
insert into product values (3,'葡萄',89)
insert into product values (4,'苹果',235)
insert into product values (5,'香蕉',77)
insert into product values (6,'芒果',34)
insert into product values (7,'葡萄',78)
insert into product values (8,'梨',24)
表中数据如:
2、如果查询name列有重复的数据,可执行sql语句:
select * from product where name in (select name from product group by name having COUNT(*)>1)
说明:查询的结果就是香蕉和葡萄在表中是有重复的,要把香蕉和葡萄的所有记录都查询出来,结果如图: - 答:如果xin表的ID是自增列,则insert
into
xin(ENAME,
SNAME,
NEWNUM)select
MIN(ENAME)
AS
ENAME,
SNAME,
count(*)
AS
NEWNUM
from
jie
group
by
SNAME只要在asp代码中执行这个sql语句就可以了 - 答:select * from 表 where b in (select b from 表 group by b having count(*)>1)
以上,希望对你有所帮助!
问:sql查询某张表中某一列的重复数据
- 答:1.sql查询某张表中某一列的重复数据
select 字段name from 表A where 字段name in (select 字段name from 表A group by 字段name having count(字段name)> 1) order by 字段name
2.sql 替换某一列的某几个值
update 表名 set 字段名 =replace(原字段名,被替换前的数值,替换后的数值)
例子:
update 表A set age = replace(age,18,20)
问:如何查出同一张表中字段值重复的记录
- 答:比如表名:student字段:学生、科目、成绩select t.学生,t.科目,t.成绩from (select count(*) num,max(学生) 学生,max(科目) 科目,max(成绩) 成绩from student stugroup by stu.学生,stu.科目,stu.成绩) twhere t.num > 1