更新中的mysql语法错误与相同的表

时间:2018-06-07 08:02:32

标签: 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'

1 个答案:

答案 0 :(得分:1)

在' 100'之后缺少一个paranthesis例如(取决于你想要的)但遗漏了一个:

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'