UPDATE zapisy SET grupa =(
SELECT
CASE
WHEN ( (YEAR(CURDATE())- YEAR(data_urodzenia)) >= 18 AND (YEAR(CURDATE())- YEAR(data_urodzenia)) <=29) THEN 1
WHEN ( (YEAR(CURDATE())- YEAR(data_urodzenia)) >= 29 AND (YEAR(CURDATE())- YEAR(data_urodzenia)) <=39) THEN 2
WHEN ( (YEAR(CURDATE())- YEAR(data_urodzenia)) >= 39 AND (YEAR(CURDATE())- YEAR(data_urodzenia)) <=49) THEN 3
WHEN ( (YEAR(CURDATE())- YEAR(data_urodzenia)) >= 49 AND (YEAR(CURDATE())- YEAR(data_urodzenia)) <=59) THEN 4
ELSE 5
END as row
FROM `zapisy`
)
如何用此触发?
答案 0 :(得分:1)
似乎你无法在触发器中完成所有这些操作。根据文件:
Within a stored function or trigger, it is not permitted to modify a table
that is already being used (for reading or writing) by the statement that
invoked the function or trigger.
根据这个答案,你似乎应该:
create a stored procedure, that inserts into/Updates the target table,
then updates the other row(s), all in a transaction.