环境:
sql
复制代码
clickhouse-client -m -h CH01--port 9001 -d test
伪MAC判断
sql
复制代码
CK通过SQL判断假MAC的示例: select has(['2','6','A','E','a','e'],SUBSTRING('03-92-26-5B-13-02',2,1) )
将MAC地址替换为字段名即可
1.相似车分析
1.1执行
sql
复制代码
SELECT length(arrayFilter((x, y) -> (x != y), arrayMap(x -> substringUTF8(HPHM, x + 1, 1), range(7)), b)) AS diffLen,HPHM
FROM
(SELECT PLATE_NO AS HPHM,['滇', '0', '1', 'A', '2', '2', '1'] AS b from CAR_DETECT_RL)
WHERE diffLen < 2 limit 10;
SELECT length(arrayFilter((x, y) -> (x != y), arrayMap(x -> substringUTF8(HPHM, x + 1,1), range(7)), b)) AS diffLen,HPHM FROM (SELECT '滇04A221' AS HPHM,['滇', '0', '1', 'A', '2', '2', '1'] AS b from numbers(3)) WHERE diffLen < 2 limit 10;
1.2结果
tex
复制代码
┌─diffLen─┬─HPHM─────┐
│ 1 │ 滇04A221 │
└─────────┴──────────┘
┌─diffLen─┬─HPHM─────┐
│ 1 │ 滇C1A221 │
└─────────┴──────────┘
┌─diffLen─┬─HPHM─────┐
│ 1 │ 滇01AD21 │
└─────────┴──────────┘
2.车辆轨迹搜车
2.1执行
sql
复制代码
--判断车辆实际运行轨迹 是否包含指定的运行轨迹
SELECT
PLATE_NO,
length(b) AS len2,
indexOf(a, b[1]) AS idx,
length(a) AS len1,
if(len1 < (len2 + idx), 100, length(arrayFilter(x -> ((a[idx + x]) != (b[x + 1])), range(len2)))) AS diffLen
FROM
(
select PLATE_NO,groupArray(DEVICE_ID) AS a,arrayDistinct(['4401000000131000301', '494583076246736505','4401000000131000320'])
AS b from (
SELECT PLATE_NO,DEVICE_ID
FROM CAR_DETECT_RL where PASS_TIME between '2019-07-01 00:00:00' and '2019-07-01 23:59:59' order by PASS_TIME
) t group by PLATE_NO
) where diffLen > 2;
SELECT PLATE_NO,
length(b) AS len2,
indexOf(a, b[1]) AS idx,
length(a) AS len1,
if(len1 < (len2 + idx), 100, length(arrayFilter(x -> ((a[idx + x]) != (b[x + 1])), range(len2)))) AS diffLen
FROM (
select '浙4C12C2' as PLATE_NO,
array('4401000000131000301', '494583076246736505','4401000000131000320') AS a,arrayDistinct(['4401000000131000301', '494583076246736505','4401000000131000320']
) AS b ) where diffLen > 2;
2.2结果
tex
复制代码
┌─PLATE_NO─┬─len2─┬─idx─┬─len1─┬─diffLen─┐
│ 浙4C12C2 │ 3 │ 11 │ 15 │ 1 │
│ 湘2D44DB │ 3 │ 3 │ 9 │ 1 │
│ 鲁B1BB1D │ 3 │ 4 │ 7 │ 1 │
│ 鲁B1CA10 │ 3 │ 2 │ 13 │ 1 │
│ 湘BAB2A2 │ 3 │ 11 │ 16 │ 1 │
│ 赣A022B2 │ 3 │ 4 │ 10 │ 1 │
│ 鲁D2B410 │ 3 │ 7 │ 11 │ 1 │
│ 云DD002C │ 3 │ 11 │ 15 │ 1 │
2.3 测试SQL
sql
复制代码
SELECT a,b,if(len1<len2+idx,100,length(arrayFilter(x-> (a[idx+x] != b[x+1]),range(len2)))) as diffLen
FROM (
SELECT arrayDistinct(['A', 'B', 'C', 'D','D','D', 'H', 'F', 'G']) AS a,
arrayDistinct(['B', 'C', 'D', 'E', 'F']) AS b,length(a) AS len1,length(b) AS len2,indexOf(a,b[1]) as idx)
where diffLen<2;