2

一个简单的查询有问题:

DELETE FROM t_meter_value mv
 INNER JOIN t_channel c ON mv.t_channel_id = c.id
      WHERE (c.t_device_device_address = 16777216 OR 
             c.t_device_device_address = 33619968)
        AND c.t_channelspec_channel_address NOT IN
            (256, 257, 259, 263, 261, 326, 271, 281, 273, 32778);

我在内部得到一个语法错误,我不知道为什么。当我使用 select 变体时,它工作正常。

4

1 回答 1

5

相反,请尝试:

delete mv from t_meter_value mv
inner join t_channel c on mv.t_channel_id = c.id
where (
    c.t_device_device_address = 16777216 or 
    c.t_device_device_address = 33619968
  ) and 
  c.t_channelspec_channel_address not in (
    256, 257, 259, 263, 261, 326, 271, 281, 273, 32778
  );

请注意,别名mv是在delete和 之间添加的from

这表明应该删除哪个表的记录...您还可以选择使用delete c from.

于 2012-12-20T18:43:19.237 回答