MySQL 带有子语句的程序? WHERE 应该在哪里,也许在 () 里面?

MySQL Procedure with sub statement? Where should WHERE be and maybe inside ()?

我一直在努力,现在它因 WHERE 子句上的错误而停止。无法找到解决方案。如果我这样做 SELECT * FROM booking_customer WHERE date_booking_customer = date_input AND time_booking_customer = time_input; 它工作得很好,但与其他的一起,WHERE...

前面有一个 varning
CREATE DEFINER=`root`@`localhost` 
PROCEDURE `book_service`(
date_input DATE,
time_input  TIME,
name_input VARCHAR (200),
member_input TINYINT,
boatname_input VARCHAR (200),
email_input VARCHAR (200),
mobile_input VARCHAR (200)
)

BEGIN
    INSERT INTO booking_customer(
    name_booking_customer, 
    member_booking_customer, 
    boatname_booking_customer, 
    mail_booking_customer, 
    mobile_booking_customer) 
    
    VALUES (
    name_input, 
    member_input, 
    boatname_input, 
    email_input, 
    mobile_input)
    
    WHERE date_booking_customer = date_input 
    AND time_booking_customer = time_input;
END

/斯万特

我不完全确定你试图用 WHERE 子句完成什么,但是 INSERT 语句不能有与之关联的 WHERE。

看起来您正在尝试更新行 WHERE date_booking_customer = date_input 和 time_booking_customer = time_input。如果这是你想要做的,你可以这样做:

UPDATE booking_customer
SET 
    name_booking_customer = name_input, 
    member_booking_customer = member_input, 
    boatname_booking_customer = boatname_input, 
    mail_booking_customer = email_input, 
    mobile_booking_customer = mobile_input
WHERE 
    date_booking_customer = date_input 
    AND time_booking_customer = time_input;

请参阅 SQL INSERT INTO 语句,https://www.w3schools.com/sql/sql_insert.asp。 INSET INTO 语句不包括 'WHERE'.

在程序中,

IF expression THEN commands
[ELSEIF expression THEN commands]
[ELSE commands]
END IF;

例如

IF date_booking_customer == date_input 
   AND time_booking_customer == time_input then
 ...
End If;