-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathck.sql
63 lines (53 loc) · 1.17 KB
/
ck.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//1.建表
create table noise (
tenantId UInt32,
deviceId UInt32,
soundPressureLevel Float64,
soundPowerLevel Float64,
ts DateTime64(3, 'Asia/Shanghai'),
date DATE
)ENGINE=MergeTree
order by (tenantId, ts)
PARTITION BY (tenantId, date)
//2.导入数据
cat noise20220101.csv | clickhouse-client --query "INSERT INTO noise FORMAT CSV" --input_format_allow_errors_num=10
//合并下noise数据
OPTIMIZE TABLE noise
//clear os cache
//sudo bash -c "echo 3 > /proc/sys/vm/drop_caches"
//3.测试
//3.1 case1
select *
from noise
where tenantId = 1055
and deviceId = 10067
and date = '2022-01-01'
order by ts asc
limit 100
//3.2 case2
select *
from noise
where tenantId = 1055
and date = '2022-01-01'
order by ts desc
limit 1 by deviceId
//3.3 case3
select
min(ts) as startTs
,max(ts) as endTs
,max(soundPressureLevel)
,avg(soundPressureLevel)
,max(soundPowerLevel)
,avg(soundPowerLevel)
from noise
where tenantId = 1055
and deviceId = 10067
and date = '2022-01-01'
and ts between '2022.01.01T00:50:15.518' and '2022.01.01T00:55:15.518'
//3.4 case4
select
*
from noise
where tenantId = 1055
and deviceId = 10067
and date = '2022-01-01'