日期:2014-05-16  浏览次数:20441 次

查出数据库中多个字段相同的行
刚开始表没有设置主键盘,后来要设置 多个字段作为主键 但是这几个字段的值有少部门是重复的,
所以要找出重复的行。

三个设置为主键的字段:c_year,c_parent,c_name
--找出重复的行
select *
  from t_qq9_gdp t
 where
 rowid != (select max(rowid)
             from t_qq9_gdp t2
            where t.c_year = t2.c_year
              and t.c_parent = t2.c_parent
              and t.c_name = t2.c_name);
--选出重复的行              
select *
  from t_qq9_gdp t
 where t.c_year = '2002'
   and t.c_parent = '拉丁美洲和加勒比海地区'
   and (t.c_name = '多米尼加共和国' or t.c_name = '危地马拉');


select c_nme,count(*) as aa from tb_user_info t
group by c_nme,c_pwd,c_enabled
order by aa desc

注意是group by  不是order by