Mysql-da IF ifodasini ishlatishda xatolik bormi?

Mysql tomonidan supermarketda odamlar sonini yangilashni xohlayman. Supermarket - bu stoldir. Shaxs - supermarketdagi odamlar soni. N - supermarketning nomi. Kamayish - supermarketda pasayish miqdorini bildiradi. Agar supermarketdagi odamlar soni 100 dan kichik bo'lsa, demak odamni 100 deb belgilang. Ushbu MySQL buyrug'i "1193 noma'lum noma'lum tizim o'zgaruvchisi" shaxsini qaytaradi. Har qanday taklif iltimos?

CREATE PROCEDURE updatePerson(IN n CHAR(10), IN decrease INT)
BEGIN
 UPDATE supermarket
 SET person = person - decrease 
 WHERE name = n;

 IF person< 100 THEN 
  SET person  = 100;
 END IF;
END
1
Yarim bilan bog'liq so'rovlardan so'ng siz faqatgina if ifodasini yopib qo'ygansiz va sehrli ishni kutishingiz mumkin.
qo'shib qo'ydi muallif Lightness Races in Orbit, manba

1 javoblar

CREATE PROCEDURE updatePerson(IN n CHAR(10), IN decrease INT)
BEGIN
 UPDATE supermarket
 SET person =case when (person - decrease) <100 then 100 else  (person - decrease) end 
 WHERE name = n;    
END

Buni ko'ring.

1
qo'shib qo'ydi