准备工作-建表
create table t_order_ins(
id UInt32 COMMENT '主键',
sn String COMMENT '订单编号',
total Decimal(11,2) COMMENT '总金额',
create_time Datetime COMMENT '创建时间'
)
engine=ReplacingMergeTree(create_time)
partition by toYYYYMMDD(create_time)
primary key(id)
order by (id, sn);
插入语句 insert
clickhourse 支持标准的 insert 语句
方式一
insert into 表名 (列名1 ,列名2 ,列名3 ) values (值1,值2,值3)
例子:
insert into t_order_ins (id ,sn ,total ,create_time) values (1,'0001',100,'2022-01-01 11:20:00')
方式二
当 值 的 数量、顺序 与表中 字段 的 数量、顺序 一致时,列名可以省略(当表中字段几十个时,可以大大节省工作量)
insert into 表名 values (值1,值2,值3)
例子:
insert into t_order_ins values (1,'0001',100,'2022-01-01 11:20:00')
插入多条数据
insert into 表名 (列名1 ,列名2 ,列名3 ) values
(值1,值2,值3),
(值1,值2,值3),
(值1,值2,值3),
或者
insert into 表名 values
(值1,值2,值3),
(值1,值2,值3),
(值1,值2,值3),
例子:
insert into t_order_ins values
(1,'0001',100,'2022-01-01 11:20:00'),
(2,'0002',200,'2022-01-02 11:30:00'),
(1,'0001',100,'2022-01-01 11:10:00'),
(3,'0003',300,'2022-01-03 10:00:00'),
根据 select 查询结果插入数据
将select查询结果插入到表中
insert into [TABLE] 表1 select * from 表2
例子:
INSERT INTO TABLE t_student_smp select sid,name,age,create_time from t_student_smp