clickhouse sql语句

查看a表的创建语句

复制代码
SHOW CREATE TABLE a;

删除表b

复制代码
DROP TABLE b;

例如:

sql 复制代码
CREATE TABLE ark_us.d_stk_info_us_polygon_cik_5_w
(
    `ticker` String,
    `t_date` DateTime64(6),
    `name` Nullable(String),
    `market` Nullable(String),
    `type` Nullable(String),
    `cik` Nullable(String),
    `primary_exchange` Nullable(String),
    `is_alter` Nullable(String),
    `data_issue` Nullable(String),
    `alter_data` Nullable(String)
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(t_date)
ORDER BY (ticker, t_date)
SETTINGS index_granularity = 8192

DROP TABLE ark_us.d_stk_info_us_polygon_cik_5_w

select语句,group by,

正则表达式:

sql 复制代码
SELECT *
                        FROM ark_us.d_stk_info_us_polygon_cik_1_w
                        WHERE (not arrayStringConcat(splitByChar('.', substring(ticker, 1))) != arrayStringConcat(splitByChar('.', replaceRegexpAll(ticker, '[a-z]', ''))))---小写字母
                            and(
                             NOT (ticker LIKE '%.%')-- ticker 不含有点
                            OR
                            -- ticker 含有点且点后只含有一个字符
                            (ticker LIKE '%._%' AND ticker NOT LIKE '%.__%'))
                            and (not ticker like '%.%.%')

对于v1表,选出两种类型,只有CS,只发生CS和NULL转变的两种cik-ticker,得到v2表

sql 复制代码
--插入数据表
insert into ark.d_stk_info_us_polygon_v2 select * from
(
	SELECT ticker, t_date, name, market, if(type IS NULL, 'CS', type)as type, cik, primary_exchange
	FROM (
	select concat(if(cik IS NULL, 'NULL', cik),
	        if(ticker IS NULL, 'NULL', ticker) ) as cik_ticker ,
	        cik,ticker,t_date,type,name,market,primary_exchange
	FROM ark.d_stk_info_us_polygon_v1
	where market = 'stocks'
	) as a_table
	RIGHT JOIN (
	    select *,concat(if(cik IS NULL, 'NULL', cik),
	        if(ticker IS NULL, 'NULL', ticker) ) as cik_ticker from (
	SELECT 
	    cik,
	    ticker,
	    groupArray(DISTINCT if(type IS NULL, 'NULL', type)) AS type_list,
	    arrayStringConcat(type_list) AS type_str
	FROM ark.d_stk_info_us_polygon_v1
	where market = 'stocks'
	GROUP BY cik,ticker
	HAVING length(type_list) >= 1
	) where   type_str in ('CS', 'CSNULL', 'NULLCS')
	) as b_table USING (cik_ticker)
)

distinct ,count(),group by having

sql 复制代码
nohup python3 data.py > output_1733.log &

相关推荐
mjhcsp8 分钟前
DeepSeek V4.1 Flash 批量处理效能实测
java·前端·数据库
ShineWinsu15 分钟前
对于Redis:Steam、Geospatial、Hyperloglog、Bitmap、Bitfield类型的解析
数据库·c++·redis·分布式·缓存·面试·zset
lie..27 分钟前
30天从零开始学AI应用开发(Day 17):ChromaDB 上手:给本地文档建一个“外挂大脑”
数据库·人工智能·oracle
code_whiter1 小时前
01-MySQL数据库基础
数据库·mysql
weixin_382395231 小时前
本地部署 ERP 选型记录:从 Excel 到轻量系统的这几年
数据库·人工智能·数据挖掘
2401_891409262 小时前
期货量化用得上的几类行情数据:逐笔、Level2、分钟线和五档tick
数据库
海绵宝宝转agent2 小时前
基于Redis ZSet+AOP+注解实现限流注解算法
数据库·redis·算法
imDwAaY3 小时前
Redis 也能做消息队列?从 Stream 的存储讲到消费确认
数据库·redis·缓存
@Mike@3 小时前
13-数据库学习笔记(查询执行处理模型)
数据库·笔记·学习
弈栈录3 小时前
MySQL 事务、索引与锁:后端开发必须掌握的数据库基础
数据库·后端