selectid,name,memo
fromA
whereidin(selectidfromAgroupbyidhavingcount(1)>=2)
1查询 abcd相同的记录:
select from F where a=b and b=c and c=d
2查询有重复数据的记录
select from F group by a,b,c,d having count()>1
3取出数据过滤到重复的数据
select distinct a,b,c,d from f
用关键字 stinct,select stinct 字段,是不重复的意思。代码的实例如下:
查询order_id和loan_lind两个字段相同的记录:
select distinct aorder_preview_id, aorder_id, aloan_kind
from ddk_order_preview_info a
join ddk_order_preview_info b
on aorder_preview_id != border_preview_id
where aorder_id = border_id and aloan_kind = bloan_kind;
扩展资料
SQL数据库查询出一张表中重复的数据,按某个字段来查找的实例:
例如表名为Course:
需要查询出name的重复,解答如下:
补充:
如:查询每个姓名出现大于2次,SQL如下
SELECT COUNT(NAME) as '出现次数', NAME FROM 表名
GROUP BY NAME HAVING count(NAME) > 2 ORDER BY 出现次数 DESC
参考资料来源:MySql官方网站-MySQL 80参考手册-13210 SELECT语法
这个是个SQL行转列的问题,例子如下:
Create table test (yhmc char(10),splb char(10),xfe int,xfsj char(10))
go
insert test values('张三','语文',80,'2007-10-01')
insert test values('张三','语文',80,'2007-10-01')
insert test values('张三','数学',86,'2007-10-01')
insert test values('张三','英语',75,'2007-10-01')
insert test values('李四','语文',78,'2007-10-01')
insert test values('李四','数学',85,'2007-10-01')
insert test values('李四','英语',78,'2007-10-01')
declare @sql varchar(8000)
set @sql = 'select yhmc'
select @sql = @sql + ',sum(case splb when '''+splb+''' then xfe end) ['+splb+']'
from (select distinct splb from test) as a
select @sql = @sql+' from test group by yhmc'
exec(@sql)
drop table test
以上SQLServer2000测试通过
我的你用的前面的Test只是我做的测试数据,你用的只是
declare @sql varchar(8000)
set @sql = 'select yhmc'
select @sql = @sql + ',sum(case splb when '''+splb+''' then xfe end) ['+splb+']'
from (select distinct splb from test) as a
select @sql = @sql+' from test group by yhmc'
exec(@sql)
然后说一句,我这个行转列只是一个把2个SQL拼在一起的方式,不好再省了,要不你做个视图放到数据库里面去,试试查询这个视图吧
3)好吧,给你一个我认为不太好的答案
select yhmc '用户名称',sum(case splb when 'A类消费'then xfe else 0 end) 'A类消费',
sum(case splb when 'B类消费'then xfe else 0 end) 'B类消费',
sum(case splb when 'C类消费'then xfe else 0 end) 'C类消费'
from test group by yhmc
以上就是关于SQL怎样查询重复数据全部的内容,包括:SQL怎样查询重复数据、sql查询按两个字段查询重复记录、数据库重复项查询等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)