You need to enable JavaScript to run this app.
ByteHouse云数仓版

ByteHouse云数仓版

复制全文
DML
删除语句 (DELETE)
复制全文
删除语句 (DELETE)

DELETE 语句用于删除目标表指定列的行数据。

使用限制

当前仅唯一键表支持使用删除语句(DELETE),其他类型的表请使用“ALTER TABLE - DELETE”语句,详情请参见删除操作(DELETE)

语法
DELETE FROM [db.]table WHERE expr;

示例
-- 引擎默认保证 unique key 在分区内的唯一性

CREATE TABLE  test.unique_table
(
  `event_time` DateTime,
  `product_id` UInt64,
  `city` String,
  `category` String,
  `amount` UInt32,
  `revenue` UInt64
)
ENGINE = CnchMergeTree
PARTITION BY toDate(event_time)
ORDER BY (city, category)
UNIQUE KEY product_id;

INSERT INTO  test.unique_table VALUES
('2020-10-29 23:40:00', 10001, 'Beijing', '男装', 5, 500),
('2020-10-29 23:40:00', 10002, 'Beijing', '男装', 2, 200),
('2020-10-29 23:40:00', 10003, 'Beijing', '男装', 1, 100);

-- 通过 DELETE FROM 来删除 revenue == 500 的数据
DELETE FROM  test.unique_table WHERE revenue = 500;
-- 通过 DELETE FROM 来删除 revenue >= 200 的数据
DELETE FROM  test.unique_table WHERE revenue >= 200;

-- 查询结果中已删除 revenue >= 200 的数据
select * from  test.unique_table order by toDate(event_time), product_id;
┌──────────event_time─┬─product_id─┬─city────┬─category─┬─amount─┬─revenue─┐
│ 2020-10-29 23:40:00 │      10003 │ Beijing │ 男装     │      1 │     100 │
└─────────────────────┴────────────┴─────────┴──────────┴────────┴─────────┘

注意

如果需要删除整个分区的数据,建议通过DROP PARTITION命令进行删除,更高效和快速,操作详情请参见DROP PARTITION|PART

最近更新时间:2025.12.25 17:41:34
这个页面对您有帮助吗?
有用
有用
无用
无用