Mysql中的伪列


Oracle中有个RowNum,Mysql中呢?今天遇到一个没有主键id的表,着实令人郁闷,只好动用伪列

DELETE FROM
hh
WHERE user_age IN(
SELECT tab.user_age FROM
(SELECT fhtab.user_age , COUNT(*) AS COUNT FROM
(SELECT @rownum:=@rownum+1 rownum,htab.* FROM
(SELECT @rownum:=0,hh.* FROM hh) htab) fhtab
GROUP BY fhtab.user_age HAVING COUNT > 1 ORDER BY fhtab.user_age) tab)
AND

 

这样肯定是不正确的,因为hh表中没有 rownum这个字段呀,,但是辛苦一番,没有功劳得有苦劳,就显示一下mysql中伪列的创建


rownum NOT IN
(SELECT mhtab.rownum FROM (SELECT MIN(fhtab.rownum) AS rownum,COUNT(*) AS COUNT FROM
(SELECT @rownum:=@rownum+1 rownum,htab.* FROM
(SELECT @rownum:=0,hh.* FROM hh) htab) fhtab
GROUP BY fhtab.user_age HAVING COUNT > 1 ORDER BY fhtab.user_age) mhtab)

posted @ 2016-05-17 13:58  江湖一笑  阅读(1527)  评论(0编辑  收藏  举报