你好我想更新或插入一个应用程序,但它显示我的错误。知道如果我删除更新或查询工作
UPDATE OR INSERT INTO stat_alert(`DAT`,`provider`,`CI`,`cell`,`BSC`,`cmts`,`nbr`,`TYPE`)
SELECT CC.DAT,CC.provider,CC.CI,CC.cell,CC.BSC,CC.cmts, CONCAT(CC.C,'C, ',MM.M ,'M') AS nbr,'C' AS TYPE FROM
(SELECT DAT,provider,CI,cell,BSC,cmts,COUNT(*) AS C FROM alertes_bss2 WHERE Criticity = 'C' GROUP BY cell,Criticity ) AS CC,
(SELECT DAT,provider,CI,cell,BSC,cmts,COUNT(*) AS M FROM alertes_bss2 WHERE Criticity = 'M' GROUP BY cell,Criticity) AS MM WHERE MM.cell = CC.cell
UNION SELECT DAT,provider,CI,cell,BSC,cmts, CONCAT(COUNT(*) ,'C') AS nbr,'C' AS TYPE FROM alertes_bss2 WHERE Criticity = 'C' AND cell NOT IN
(SELECT cell FROM alertes_bss2 WHERE Criticity = 'M') GROUP BY DAT,provider,CI,cell,BSC,Criticity
UNION SELECT DAT,provider,CI,cell,BSC,cmts, CONCAT(COUNT(*) ,'M') AS nbr,'M' AS TYPE FROM alertes_bss2 WHERE Criticity = 'M' AND cell NOT IN
(SELECT cell FROM alertes_bss2 WHERE Criticity = 'C') GROUP BY DAT,provider,CI,cell,BSC,Criticity;
我有这个错误:
Query: UPDATE OR INSERT INTO stat_alert(`DAT`,`provider`,`CI`,`cell`,`BSC`,`cmts`,`nbr`,`TYPE`) SELECT CC.DAT,CC.provider,CC.CI,CC.cell...
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 'OR INSERT INTO stat_alert(`DAT`,`provider`,`CI`,`cell`,`BSC`,`cmts`,`nbr`,`TYPE' at line 1
Execution Time : 0 sec
Transfer Time : 0 sec
Total Time : 0.003 sec
---------------------------------------------------
谁能帮助我
答案 0 :(得分:2)
也许您正在寻找REPLACE
? link
REPLACE的工作原理与INSERT完全相同,只是如果在一个旧行中 table与PRIMARY KEY或UNIQUE的新行具有相同的值 index,在插入新行之前删除旧行。
答案 1 :(得分:0)
你不能一起使用UPDATE AND INSERT ...............
您需要在代码中处理它,无论是需要更新数据还是插入数据。
答案 2 :(得分:0)
你不能在Mysql中使用UPDATE OR INSERT
。你必须检查记录是否存在于数据库中。如果它存在,那么UPDATE
否则使用INSERT
。