求查找重复记录的SQL语句 本帖最后由 huayy 于 2011-12-12 09:53:35 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select * from table where a_user = '涛涛' and a_integral = 100你想要实现什么啊?说清楚点 你用的什么数据库?数据库不同,sql语句不同的 我们用的是Oracleselect a.* from table a,table b where a.a_user = b.a_user and a.a_integral = b.a_integral 试试这个,刚才那个是没吕清楚 额,抱歉,是mssql 数据库。。 mysql应该也可以给表起别名,你先试试我给你的第二条可以用不,不行我给你现查书 select * from tb awhere exists(select 1 from tb where a_user=a.a_user and id<>a.id) 表结构ID a_user a_title a_integral1 涛涛 购买商品XXX获得积分 1002 宝宝 购买商品CCC获得积分 503 平平 购买商品DDD获得积分 604 涛涛 购买商品TTT获得积分 100实现下面的显示ID a_user a_title a_integral1 涛涛 购买商品XXX获得积分 1004 涛涛 购买商品TTT获得积分 100即a_user相同、且a_integral相同的两条或以上的数据. 可以使用T_sql 的交集 Intersect select * from a_userIntersect select * from a_integral你试试 如果还有语法的问题 你可以看看帮助文档 但是用Intersect 是可以实现你的需求的 select* from table1 a where (select count(1) from table1 where a_user= a.a_user and a_integral = a.a_integral) 用distinct 语句可以过滤出来相同的 select a_user ,a_integral from table group by a_user ,a_integral having count(a_user)>1 and count(a_integral)>1 忘记写判断条件了、、、select* from table1 a where (select count(1) from table1 where a_user= a.a_user and a_integral = a.a_integral) >1 或者这样效率高一点,如果ID是主键的话,select * from table1 a where not exists(select 1 from table1 where id<>a.id and a_user= a.a_user and a_integral =a.a_integral) 把 not 去掉,写错了 select * from tbName awhere exists(select 1 from tbName where a_user=a.a_user and a_integral =a.a_integral and id<>a.id) 前后台字符编码转换问题 GridView合并指定列(在线等,解决了100分全给) 程序长时间不执行会出现这个错误 iframe问题 一台服务器有两个服务,有什么办法用一个服务显示另一个服务下的图片? RegisterHiddenField取值和重赋值 List<>的数据怎么读取? 大家请进,谈下技术人员如何创业 请问如何在VS.NET中在javascript中设置断点呢?谢谢 请问哪里有asp.net(C#)+SQLServer空间申请? 计算每个月有多少周,和某年月多少周?求高手指点!! 请问,webBrowser如何给一个没有ID,name使用单引号的input填充数据?
select a.* from table a,table b where a.a_user = b.a_user and a.a_integral = b.a_integral
试试这个,刚才那个是没吕清楚
where exists(select 1 from tb where a_user=a.a_user and id<>a.id)
1 涛涛 购买商品XXX获得积分 100
2 宝宝 购买商品CCC获得积分 50
3 平平 购买商品DDD获得积分 60
4 涛涛 购买商品TTT获得积分 100
实现下面的显示
ID a_user a_title a_integral
1 涛涛 购买商品XXX获得积分 100
4 涛涛 购买商品TTT获得积分 100即a_user相同、且a_integral相同的两条或以上的数据.
select * from a_user
Intersect
select * from a_integral你试试 如果还有语法的问题 你可以看看帮助文档 但是用Intersect 是可以实现你的需求的
select* from table1 a where (select count(1) from table1 where a_user= a.a_user and a_integral = a.a_integral)
select a_user ,a_integral from table group by a_user ,a_integral having count(a_user)>1 and count(a_integral)>1
select* from table1 a where (select count(1) from table1 where a_user= a.a_user and a_integral = a.a_integral) >1
(select 1 from table1 where id<>a.id and a_user= a.a_user and a_integral =a.a_integral)
where exists(select 1 from tbName where a_user=a.a_user and a_integral =a.a_integral and id<>a.id)