Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果在mysql insert语句中_Mysql_Sql_Syntax Error - Fatal编程技术网

如果在mysql insert语句中

如果在mysql insert语句中,mysql,sql,syntax-error,Mysql,Sql,Syntax Error,我想做这样的事情: IF ((19, 13) NOT IN (select idUtente, IdLezione from partecipa)) THEN insert into partecipa (IdUtente, IdLezione, IdAbbonamento, utente, prova, riserva) values( 19, 13, (select idAbbonamento from abbonamento where attivo=1 a

我想做这样的事情:

 IF ((19, 13) NOT IN (select idUtente, IdLezione from partecipa)) THEN
 insert into partecipa 
 (IdUtente, IdLezione, 
 IdAbbonamento, 
 utente,
  prova, riserva) 
 values( 
 19, 13, 
 (select idAbbonamento from abbonamento where attivo=1 and idUtente=19), 
 (select concat(u.nome," ",u.cognome) from abbonamento as a, utente as u where      a.attivo=1 and a.idUtente=u.idUtente and u.idUtente=19),
  0, 0)
 end if;
但是语法中有一个错误

Error Code: 1064. 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 'IF ((19, 13) NOT IN (select idUtente, IdLezione from partecipa)) THEN insert int' at line 1    0.000 sec 
在互联网上我找不到任何解决办法。有人能帮我吗?

试试这个:

INSERT INTO partecipa (IdUtente, 
                       IdLezione, 
                       IdAbbonamento, 
                       utente,  
                       prova, 
                       riserva)
SELECT 
  19, 
  13, 
  ab.idAbbonamento,  
  concat(u.nome, ' ', u.cognome), 
  0, 
  0
FROM abbonamento       AS ab 
INNER JOIN abbonamento AS a  ON ab.attivo   = a.attivo 
                            AND ab.idUtente = a.idUtente
INNER JOIN utente      AS u  ON a.idUtente  = u.idUtente 
WHERE a.attivo   = 1
  AND u.idUtente = 19
  AND NOT EXISTS(SELECT 1 
                 FROM partecipa 
                 WHERE idUtente  = 19 
                   AND IdLezione = 13);

错误信息是什么?请回答另一个问题。。。如果我需要在不从其他表中选择值的情况下执行此类操作,则需要插入特定值(如果该值不存在)。@user1856906是的,在这种情况下,您必须直接插入这些值。