0

您好,我想更新或插入应用程序,但它显示错误。知道如果我删除更新或查询有效

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

谁能帮我

4

3 回答 3

2

也许你正在寻找REPLACE关联

REPLACE 的工作方式与 INSERT 完全相同,只是如果表中的旧行与 PRIMARY KEY 或 UNIQUE 索引的新行具有相同的值,则在插入新行之前删除旧行。

于 2012-11-08T11:36:27.643 回答
0

您不能同时使用 UPDATE 和 INSERT ......

您需要在代码中处理它是否需要更新数据或插入数据。

于 2012-11-08T11:33:38.043 回答
0

您不能UPDATE OR INSERT在 Mysql 中使用。您必须检查记录是否存在于数据库中。如果存在则UPDATE使用INSERT.

于 2012-11-08T11:40:13.077 回答