当前位置: 代码迷 >> Java Web开发 >> 剔除除了自动编号不同,其他都相同的学生冗余信息
  详细解决方案

剔除除了自动编号不同,其他都相同的学生冗余信息

热度:3603   发布时间:2013-02-25 21:08:34.0
删除除了自动编号不同,其他都相同的学生冗余信息
有如下学生表
自动编号 学号 姓名 课程编号 课程名称 分数
1 2005001 张三 0001 数学 69
2 2005002 李四 0001 数学 89
3 2005001 张三 0001 数学 69
要求:删除除了自动编号不同,其他都相同的学生冗余信息

我是这么写的
DELETE from score where id not in(select min(id) from score GROUP by name,kecheng,fenshu);

但是不对
在网上查了查按照下面的写法就对了
DELETE from score where id not in (select bid from (select min(id) as bid from score GROUP by name,kecheng,fenshu)as b);

谁能解释一下吗?
------最佳解决方案--------------------------------------------------------
DELETE from score where  (name,kecheng,fenshu) in(select name,kecheng,fenshu from score GROUP by name,kecheng,fenshu having count(name,kecheng,fenshu) > 1) ;
------其他解决方案--------------------------------------------------------
DELETE from score where id not in(select min(id) id from score GROUP by name,kecheng,fenshu);
这样应该就可以了吧。你的子句里面没有叫id的,所以不对吧。你试试,给min(id)加上别名id


------其他解决方案--------------------------------------------------------
都对啊 为什么不对呢
------其他解决方案--------------------------------------------------------
知道原因了  mysql自身的问题
  相关解决方案