首页 > 解决方案 > mysql 在同一张表的更新中出现语法错误

问题描述

显示的错误

1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在附近使用的正确语法

我认为语法错误

update invoice AS t1, 

(select sum(total_cost) from invoice where billno='X-0125' and item='11') AS t2 

set t1.total_cost=(t1.total_cost/(t2.sum(total_cost))*100
                
WHERE t1.billno='X-0125' and t1.item='11'

标签: mysql

解决方案


例如,在“100”之后缺少一个括号(取决于您想要什么)但缺少一个:

update
  invoice AS t1,
  (
    select
      sum(total_cost)
    from
      invoice
    where
      billno = 'X-0125'
      and item = '11'
  ) AS t2
set
  t1.total_cost =(t1.total_cost /(t2.sum(total_cost)) * 100)
WHERE
  t1.billno = 'X-0125'
  and t1.item = '11'

推荐阅读