如果在mysql插入语句中

编程入门 行业动态 更新时间:2024-10-24 14:25:22
本文介绍了如果在mysql插入语句中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想做这样的事情:

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

在互联网上我找不到任何解决方案.有人可以帮我吗?

and on internet I can't find any solution. Someone can help me?

推荐答案

试试这个:

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);

更多推荐

如果在mysql插入语句中

本文发布于:2023-10-18 10:46:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504004.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!