0

我正在处理一些 Mysql 任务,并被要求:

所有担任经理的员工(领导者,“L”型)的工资增长 6%。

我尝试使用这种方法:

UPDATE employee
SET salary = salary * '1,06'
WHERE emptype = 'L';

我收到一条错误消息错误代码:1292。截断不正确的 DOUBLE 值:'1,06'

当我尝试描述员工时;

我可以看到薪水是类型 int(11)

有人可以告诉我做错了什么以及正确的编码是怎样的,是否可以在不更改类型的情况下将这 6% 添加到当前值?

4

1 回答 1

3

It should be this...

UPDATE employee
SET salary = salary * 1.06
WHERE emptype = 'L';

... instead. Not only '1,06' is a string - it's a string that cannot be cast into a corresponding numeric value without losing some data ('truncating', in other words) in process, as comma isn't treated as a decimal part separator - a dot is.

And that's exactly what MySQL tells you in this error message. It's just that subtle difference between a number and its string representation you've probably missed.

于 2013-10-16T21:40:19.547 回答