我有两个Joined select语句,我想要交换排名。我加入的select语句是:
SELECT l.id, r.id, l.rank, r.rank, l.oldurl, r.oldurl, l.newurl, r.newurl
FROM (SELECT * FROM as795_sh404sef_urls WHERE newurl REGEXP 'Itemid\=108' AND rank<>0 GROUP BY oldurl HAVING MAX(id)) AS l
JOIN (SELECT * FROM as795_sh404sef_urls WHERE rank=0 GROUP BY oldurl) AS r
ON l.oldurl=r.oldurl;
我正在尝试创建一个更新语句,它将交换排名。只是说l.rank应该在所有情况下都变为0,在这种情况下r.rank应该变成什么是l.rank
UPDATE (SELECT id FROM as795_sh404sef_urls WHERE rank=0 AND oldurl='zumba-gold-8.html' GROUP BY oldurl) r
JOIN (SELECT * FROM as795_sh404sef_urls WHERE newurl REGEXP 'Itemid\=108' AND rank<>0 AND oldurl='zumba-gold-8.html' GROUP BY oldurl HAVING MAX(id)) l
ON l.oldurl=r.oldurl
SET r.rank= l.rank, l.rank=0;
使用此更新语句,我得到r和l表无法更新。