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

排序更新前几条的问题
我有一个表 表结构如下

-- Table "test1" DDL

CREATE TABLE `test1` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Content` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `Level` int(11) DEFAULT NULL,
  `Push` int(11) DEFAULT '-1',
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;


然后是这样 

我想创建一个update语句 

目的是按照level的大小进行排序后取前十条,修改这十条Push字段为0

我开始写的是update test1 set Push = '0' where Push='-1' order by Level limit 10

但是经过测试 order by 好像写在update后面没有作用

不知道怎么实现比较好

------解决方案--------------------
SQL code
update test1 A,(
select   id
from test1
order by level
limit 10)B
set A.push=0
where A.id=B.id;