我是新人,非常感谢帮助!!如果一个或多个" ID"需要删除行。缺少时间戳。例如,在下表中,ID = 10没有IRIG_Time = 2014-05-15 09:05:00.000的值,因此我需要删除该时间戳的所有IRIG_Time行。我使用以下查询来提取数据(感谢Barmar到目前为止的帮助!)。
CREATE TABLE Table1
SELECT *
FROM originaltable Where IRIG_Time between '2014/05/15 09:05' and '2014/05/15 09:35';
DELETE t.* FROM Table1 AS t
JOIN (
SELECT IRIG_Time
FROM Table1
GROUP BY IRIG_Time
HAVING COUNT(*) != 5
) AS t1 ON t.IRIG_TIME = t1.IRIG_TIME;
select * from Table1;
IRIG_Time ID MagnitudeA
2014-05-15 09:05:00.000 5 730406000
2014-05-15 09:05:00.000 15 742456000
2014-05-15 09:05:00.000 20 731190000
2014-05-15 09:05:00.000 25 748572000
2014-05-15 09:05:00.033 5 730343000
2014-05-15 09:05:00.033 10 755865000
2014-05-15 09:05:00.033 15 742347000
2014-05-15 09:05:00.033 20 731168000
2014-05-15 09:05:00.033 25 748574000
2014-05-15 09:05:00.067 5 730420000
2014-05-15 09:05:00.067 10 755767000
2014-05-15 09:05:00.067 15 742310000
2014-05-15 09:05:00.067 20 731176000
2014-05-15 09:05:00.067 25 748524000
当使用上面的代码时,我得到错误代码:1175您正在使用安全更新模式,并且您尝试更新没有使用KEY列的WHERE的表要禁用安全模式,请在Preferences - >中切换选项。 SQL查询并重新连接。
答案 0 :(得分:0)
DELETE t.* FROM table AS t
JOIN (
SELECT IRIG_Time
FROM table
GROUP BY IRIG_Time
HAVING COUNT(*) != (SELECT COUNT(DISTINCT ID) FROM table)
) AS t1 ON t.IRIG_TIME = t1.IRIG_TIME
答案 1 :(得分:0)
感谢巴马的帮助!我不得不修改"安全更新"首选项,但以下脚本有效!
Drop table Table1;
CREATE TABLE Table1
SELECT IRIG_Time, ID, MagnitudeA FROM originaltable
Where IRIG_Time between '2014-05-25 13:00' and '2014-05-25 14:00' order by IRIG_Time;
DELETE t.* FROM Table1 AS t
JOIN (
SELECT IRIG_Time, ID
FROM Table1
GROUP BY IRIG_Time
HAVING COUNT(*) != 5
) AS t1 ON t.IRIG_TIME = t1.IRIG_TIME;
select * from Table1;