目录

create

Insert

alter

update

aggregation


安装之流直接略过,就是下载四个包然后rpm安装。

登录默认没密码,用

clickhouse-client -m

直接登录进去就是类似于mysql的交互式界面(类似于mysql -h XXX -p)

-m指的是multiline,表示单次输入可以换行;

create

CREATE TABLE learnClickhouse.student
(`id` UInt64,`name` String,`age` UInt32,`HaveMoney` Float64,`attrb` UInt32,`create_time` DateTime
)
ENGINE = MergeTree
PARTITION BY toYYYYMMDD(create_time)
ORDER BY id
SETTINGS index_granularity = 8192 

Insert

只显示部分示例,其他的自己按需加入

insert into student(*) values (7,'朱竹青ghostcatwith great attack power',22,150000,'2000-12-31 00:00:00');
insert into student(*) values (6,'小舞hunshou魂兽MonsterBeingGod',22,150000,'2000-12-11 00:00:00');

普通select

select * from student;

类似mysql的语法

结果:

1 rows in set. Elapsed: 0.003 sec. littleserver :) select * from student;SELECT *
FROM studentQuery id: 9fa0f544-664d-4d1a-98b3-9524e5da1485┌─id─┬─name───────────────────────────┬─age─┬─HaveMoney─┬─attrb─┬─────────create_time─┐
│  6 │ 小舞hunshou魂兽MonsterBeingGod │  22 │    150000 │     2 │ 2000-12-11 00:00:00 │
└────┴────────────────────────────────┴─────┴───────────┴───────┴─────────────────────┘
┌─id─┬─name───┬─age─┬─HaveMoney─┬─attrb─┬─────────create_time─┐
│  4 │ 戴沐白 │  23 │    150000 │     2 │ 1999-08-01 00:00:00 │
└────┴────────┴─────┴───────────┴───────┴─────────────────────┘
┌─id─┬─name──────────────────────────────────┬─age─┬─HaveMoney─┬─attrb─┬─────────create_time─┐
│  7 │ 朱竹青ghostcatwith great attack power │  22 │    150000 │     2 │ 2000-12-31 00:00:00 │
└────┴───────────────────────────────────────┴─────┴───────────┴───────┴─────────────────────┘
┌─id─┬─name─────┬─age─┬─HaveMoney─┬─attrb─┬─────────create_time─┐
│  5 │ 宁荣rong │  22 │    150000 │     2 │ 2000-12-01 00:00:00 │
└────┴──────────┴─────┴───────────┴───────┴─────────────────────┘
┌─id─┬─name────┬─age─┬─HaveMoney─┬─attrb─┬─────────create_time─┐
│  3 │ tangsan │  22 │    200000 │     2 │ 2000-08-01 00:00:00 │
└────┴─────────┴─────┴───────────┴───────┴─────────────────────┘
┌─id─┬─name──────┬─age─┬─HaveMoney─┬─attrb─┬─────────create_time─┐
│  1 │ zengyanru │  26 │    300000 │     1 │ 1995-08-26 13:23:52 │
│  1 │ zhaoliang │  27 │    300000 │     1 │ 1995-08-26 13:23:52 │
└────┴───────────┴─────┴───────────┴───────┴─────────────────────┘
┌─id─┬─name───┬─age─┬─HaveMoney─┬─attrb─┬─────────create_time─┐
│  4 │ 奥斯卡 │  23 │    150000 │     2 │ 1999-09-01 00:00:00 │
└────┴────────┴─────┴───────────┴───────┴─────────────────────┘8 rows in set. Elapsed: 0.008 sec. 

clickhouse自己按照时间的分区,没有合并,用optimize也没有合并。后续估计要重启才能合并了。

alter

加字段

alter table student add column `attrb` UInt32 after `HaveMoney`;

update

update比较特殊,是用alter来做的 ,这个和clickhouse列式设计有关,毕竟人家拿来做OLAP的,本来就假定改动不多。每次都是很heavy的操作

alter table student update attrb=1 where id=1;

结果:

ALTER TABLE studentUPDATE attrb = 1 WHERE id = 1Query id: 9df3638d-09ee-46f5-a793-bcda051180adOk.0 rows in set. Elapsed: 0.009 sec.

aggregation

是clickhouse的长处,大量有用的函数供选择。原本行式存储我们印象中以为要很慢的,一想到列式存储,就发现很快。函数可以参考

count | ClickHouse Documentation

group by有几种模式可以选择,下面展示roll up(给定n个维度,会给你从左到右n个维度依次聚合一次,还有全部聚合一次)

select attrb, age, sum(HaveMoney) from student group by attrb,age with rollup;

结果

Query id: d1254ec4-2d65-4704-a6fc-ff2b3306daa2┌─attrb─┬─age─┬─sum(HaveMoney)─┐
│     1 │  26 │         300000 │
│     2 │  22 │         650000 │
│     1 │  27 │         300000 │
│     2 │  23 │         300000 │
└───────┴─────┴────────────────┘
┌─attrb─┬─age─┬─sum(HaveMoney)─┐
│     2 │   0 │         950000 │
│     1 │   0 │         600000 │
└───────┴─────┴────────────────┘
┌─attrb─┬─age─┬─sum(HaveMoney)─┐
│     0 │   0 │        1550000 │
└───────┴─────┴────────────────┘7 rows in set. Elapsed: 0.008 sec. 

其他聚合可以参考:

GROUP BY | ClickHouse Documentation

clickhouse初体验之create insert update select group by相关推荐

  1. Create and Drop Database, Create, Alter and Drop Tables, Select, Insert, Update, Delete Commands

    此文仅做自我学习记录用!!! Introduction (Descriptive) Content:- Creating and Maintaining Tables, Objectives, The ...

  2. update set from 以及表 数据的复制 insert into select from ....

    insert into ... select  from ... 工作中的示例: 初始化数据 INSERT INTO "db_gyfw"."t_fa_capz" ...

  3. mysql之DML(SELECT DELETE INSERT UPDATE)

    DML:数据操作语言     INSERT     DELETE     SELECT     UPDATE SELECT:     SELECT SELECT-LIST FROM TBNAME|TB ...

  4. oracle数据库【表复制】insert into select from跟create table as select * from 两种表复制语句区别...

    create table  as select * from和insert into select from两种表复制语句区别 create table targer_table as select ...

  5. oracle insert into as select,比较create table as select * 与 insert into table select *

    实验环境: SYS@aaron> select * from v$version; BANNER ------------------------------------------------ ...

  6. vue create()获取ref_vue-next+typescript 初体验

    无意间又一次刷到了尤大介绍 Vue 3 的文章,这次决定试一下 Vue 3 的 TypeScript 支持到底如何,不管别人说什么,只有自己用的舒服才是真的舒服.Vue 2 可是因为 ts 的缘故被喷 ...

  7. Mysql中update select更新数据,insert ignore into

    在mysql中一般更新我们都是通过 update set指定的值,但是有些时候,我们数据库中存在一些记录,这时候我们希望用已有数据库中的记录来进行更新,这时候我们可以通过mysql的update se ...

  8. oracle中create table as和insert into select语句

    SELECT INTO , INSERT INTO SELECT 和 CREATE TABLE AS SELECT INSERT INTO SELECT Create table newTable a ...

  9. SQL On Linux 初体验

    SQL On Linux初体验 备注:Blog具有时效性, 内容随着更新会发现变化,时间是2017年5月22日 SQL On Linux版本很快就会正式发布,本文进行了安装和常用的操作,感受还不错,废 ...

最新文章

  1. 文件控制 fcntl函数具体解释
  2. SAP QM初阶事务代码QA11对检验批做UD时出现很多UD Code的选择集?
  3. 自定义Title(可以实现类似于携程网上价格的显示方式)
  4. 以为Swing没人用了,原来群友们都是如此优秀!
  5. AMDD 一个把大问题分成小问题的优化算法
  6. 信息系统项目管理师:第1章:信息化与信息系统(2)-重点汇总
  7. 常用的后端命令 【笔记】
  8. String path = request.getContextPath
  9. 人人商城人人店人人分销商城V2.8.0解密开源版,收银台+秒杀+区域代理+积分商城+多商户
  10. NB-IOT开发实战
  11. 【电机控制入门】——电机控制书籍推荐
  12. 计算机游戏教学法PPT,幼儿园语言游戏教学法PPT课件
  13. 试试54款开源服务器软件 (比较知名的软件大集合)
  14. 导航上显示某个地点已关闭什么意思_想要玩好iPhone手机,6个关闭、4个开启,要牢记...
  15. Win10磁盘占用达到100%,优化一下就解决了
  16. 职场中你的岗位竞聘PPT是怎么做的?
  17. 各种依赖库(转载地址:https://blog.csdn.net/as89751)
  18. stegsolve下载
  19. Windows 10下打印机不能打印Office文件解决办法
  20. HT全矢量化的图形组件设计

热门文章

  1. 我用Python模拟了谷爱凌的凌空一跃
  2. 人在职场:可以让你少奋斗10年的工作经验
  3. PBR来龙去脉篇一:光和人眼感知颜色
  4. 用于即使在太空中也能随时随地进行编码的移动应用程序
  5. php 关注微信触发事件,微信api 关注事件
  6. 什么是PCB沉金?为什么要沉金?
  7. 论文解读 Search to Distill: Pearls are Everywhere but not the Eyes,神经网络架构搜索+知识蒸馏
  8. PHP 使用FPDF 处理中文遇到的坑
  9. scratch3.0自定义logo
  10. 自主性: 一个概念的哲学考察