1.毫秒数根据指定时区转timestamp,并计算时间差
根据毫秒数截取整时起点:毫秒数-毫秒数%(60*60*1000)
根据毫秒数截取整天起点:毫秒数-毫秒数%(24*60*60*1000)
select
pk_day,
from_unixtime(to_unixtime(now()), 'GMT'),
from_unixtime(pk_day / 1000, 'GMT'),
date_diff('day',from_unixtime(pk_day / 1000, 'GMT'),from_unixtime(to_unixtime(now()), 'GMT'))
from (values 1657171485000) as t (pk_day)
2.列转行
SELECT
CAST(json_extract(myj, '$.chainid') AS VARCHAR) chainid ,
CAST(json_extract(myj, '$.project') AS VARCHAR) project ,
CAST(json_extract(myj, '$.tokenaddr') AS VARCHAR) tokenaddr ,
CAST(json_extract(myj, '$.pooladdr') AS VARCHAR) pooladdr
FROM(
SELECT jsonarray_str,myj FROM( testonly_table CROSS JOIN UNNEST(CAST(json_parse(jsonarray_str) AS array(json))) t (myj))
)
3.md5
lower(to_hex(md5(to_utf8(concat(col1,col2)))))
-- 16进制转为10进制,例
from_base(substr(lower(to_hex(md5(to_utf8('0x0246b1b9af538ead448314bfb30bdc9e325c2af1140ffb6f438a8ea815f7a2ca')))),1,3), 16)
4.substr
下标起始位置是从1开始的
select substr('tommy',1,3)返回'tom'