V
V
vasilevconstantine2015-12-09 00:56:16
MySQL
vasilevconstantine, 2015-12-09 00:56:16

How to fix syntax error?

The whole task sounds like this:
It is necessary to draw up a "Payroll" (salary-13%). If there are minor children, one minimum wage is not taxed.
Employees
5ac4b0b32c1b406787ba411759818169.png
Children
0212b0db9f434b87a38382c1b52538f6.png
Positions: The
7dab980a45734d1fb17103ba34945c75.png
catch is that it is not possible to check the age of majority of the eldest child.

case when ( year(now()) - year(select Дети.birth from Дети,Сотрудники where Сотрудники.pers_number = Дети.pers_number_parr order by Дети.birth limit 1)<=18) then

Here is the program code in its entirety:
select pers_number,fio,
case when ( year(now()) - year(select Дети.birth from Дети,Сотрудники where Сотрудники.pers_number = Дети.pers_number_parr order by Дети.birth limit 1)<=18) then 
0.87*(select salary from Должности where Должности.name_pos=Сотрудники.position)-0.13*5965 else 
(
    (select salary from Должности where Должности.name_pos=Сотрудники.position)*0.87
)
end as salary
from Сотрудники;

MySql swears at the syntax:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where year(now()) - year(select Дети.birth from Дети,Сотрудник' at line 2

Please help me find the cause of the error.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
carry-y, 2015-12-09
@carry-y

well, firstly, in the second query, select pers_number, fio, the comma is superfluous

A
Alexey Ukolov, 2015-12-09
@alexey-m-ukolov

Well, he swears correctly, read the case documentation . You need an if, on the same page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question