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 &

相关推荐
m0_623955661 小时前
Oracle使用SQL一次性向表中插入多行数据
数据库·sql·oracle
阿蒙Amon2 小时前
C#读写文件:多种方式详解
开发语言·数据库·c#
东窗西篱梦2 小时前
Redis集群部署指南:高可用与分布式实践
数据库·redis·分布式
就是有点傻3 小时前
C#如何实现中英文快速切换
数据库·c#
jnrjian3 小时前
Oracle RAC环境 加错数据文件 的修复 归档非归档都没问题
sql·oracle
1024小神3 小时前
hono框架绑定cloudflare的d1数据库操作步骤
数据库
KellenKellenHao5 小时前
MySQL数据库主从复制
数据库·mysql
@ chen5 小时前
Redis事务机制
数据库·redis
KaiwuDB6 小时前
使用Docker实现KWDB数据库的快速部署与配置
数据库·docker
一只fish6 小时前
MySQL 8.0 OCP 1Z0-908 题目解析(16)
数据库·mysql