www.1862.net > SQl语句查询表中一个字段,去掉重复的记录

SQl语句查询表中一个字段,去掉重复的记录

select distinct 班级 FROM 表名称

可用group by……having来实现。 可做如下测试: 1、创建表插入数据: create table test(id int,name varchar(10))insert into test values (1,'张三')insert into test values (2,'李四')insert into test values (3,'张三')insert into test va...

SELECT * FROM tab WHERE C in ( SELECT C FROM tab GROUP BY C HAVING COUNT(A) > 1 )

select id, name, memo from A where id in (select id from A group by id having count(1) >= 2)

关键字Distinct 去除重复,如下列SQL,去除Test相同的记录; select distinct Test from Table 如果是要删除表中存在的重复记录,那就逻辑处理,如下: select Test from Table group by Test having count(test)>1 先查询存在重复的数据,后面...

with A as(SELECT user_id,MAX(pro_id) pro_id FROM dbo.Product_new GROUP BY user_id) select B.* from Product_new B join A on B.user_id=A.user_id and B.pro_id=A.pro_id

查看可用如下方法: 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...

关键字Distinct 去除重复 如下列SQL,去除Test相同的记录; select distinct Test from Table 如果是要删除表中存在的重复记录,那就逻辑处理,如下: select Test from Table group by Test having count(test)>1 先查询存在重复的数据,后面...

select * from tablename where 重复字段1 in (select 重复字段1 from tablename group by 重复字段1,重复字段2 having count(*)>1)。 SQL重复记录查询方法:1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select * fro...

SELECT * FROM 表 WHERE id IN (select MAX(id) from 表 GROUP BY name);

网站地图

All rights reserved Powered by www.1862.net

copyright ©right 2010-2021。
www.1862.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com