Home  >  Article  >  Backend Development  >  MySQL的Update的使用,该如何处理

MySQL的Update的使用,该如何处理

WBOY
WBOYOriginal
2016-06-13 13:39:27785browse

MySQL的Update的使用
MySQL的更新语句update中可以用子查询吗?

 update score set 姓名='王五' where 总分=(select min(总分) from score);

我这样用为什么出错?

/*******************
CREATE TABLE IF NOT EXISTS score(
学号 BIGINT UNSIGNED,
姓名 varchar(10),
数学 TINYINT UNSIGNED,
英语 TINYINT UNSIGNED,
物理 TINYINT UNSIGNED,
计算机综合 TINYINT UNSIGNED,
总分 int UNSIGNED
);

已确保各字段数据正确插入
********************/


求教!

------解决方案--------------------
这样试试,

update score set …… where 总分 in ( SELECT * FROM (SELECT min(总分) AS 总分 FROM score)t)
------解决方案--------------------

SQL code
 update score set 姓名='王五' order by 总分 asc limit 1;
<br><font color="#e78608">------解决方案--------------------</font><br>
mysql中 update的表 不能出现在第一层的子查询中,参考4楼的方法让表绕过第一层子查询
<br><font color="#e78608">------解决方案--------------------</font><br>试一下不就知道了<br>
SQL code
UPDATE score  SET 数学=(SELECT 数学 FROM (SELECT MIN(数学) AS 数学 FROM score )t)-4 WHERE 姓名='王五'; <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn