有一个表,是记录员工的学历资料,字段如下:
ygid      员工ID号
qxl        如果该项学历为员工的前学历,则为true,否则为false现在的问题是由于录入人员的疏忽,给一些员工的学历选择了多个前学历,由于在做系统时没有想到这点,在录入程序时没有进行判断,所以现在数据库里一些员工有多个前学历,要怎样才能把这些人找出来?

解决方案 »

  1.   

    select *,count(qxl) from table group by ygid having count(qxl)>1;
      

  2.   

    select ygid,count(ygid) as num from tbname group by ygid having count(ygid)>1;
      

  3.   

    rl=> select *,count(qxl) from xuelijiaoyu group by qxl having count(qxl)>1;
    错误:  字段 "xuelijiaoyu.id" 必须出现在 GROUP BY 子句中或者在聚集函数中使用
      

  4.   

    select ygid,count(ygid) as num from tbname group by ygid having count(ygid)>1
      

  5.   

    ysql> select * from test;
    +------+----------+
    | uid  | name     |
    +------+----------+
    |  111 | leox     | 
    |  112 | leoxqing | 
    |  111 | leoxq    | 
    |  113 | leoxqi   | 
    +------+----------+
    4 rows in set (0.00 sec)mysql> select *,count(uid) from test group by uid having count(uid)>1;
    +------+------+------------+
    | uid  | name | count(uid) |
    +------+------+------------+
    |  111 | leox |          2 | 
    +------+------+------------+
    1 row in set (0.00 sec)
    呵呵。。看走眼了。
      

  6.   

    select ygid
    from 表 
    where qxl=true
    group by ygid
    having count(*)>1