update或delete语句里含有子查询时,子查询里的表不能在update或是delete语句中,如含有运行时会报错;但select语句里含有子查询时,子查询里的表可以在select语句中。

如:把总成绩小于100的学生名称修改为天才

select stu_id from score group by stu_id having sum(grade)<100; #查询总成绩小于100的学生ID
update students set name='天才' where id in (select stu_id from score group by stu_id having sum(grade)<100);

 

另外,做查询时,能用单表就不要用多表。这样一来,逻辑清晰,出错的概率也就少多了。

相关文章:

  • 2021-10-19
  • 2021-12-15
  • 2021-08-08
  • 2021-11-24
  • 2021-09-07
  • 2021-07-04
  • 2021-08-09
猜你喜欢
  • 2021-12-05
  • 2018-10-09
  • 2021-05-07
  • 2021-11-19
  • 2021-11-14
  • 2021-09-28
  • 2021-12-05
  • 2021-10-02
相关资源
相似解决方案