Repository navigation
Closed
Labels
Description
summary
I want to get output by element count of array 😅 I tried for a long time and didn't know how to write this sql. Please help me.
source data
select * from app_log_local;
app=x1, number_keys = [k1]
app=x1, number_keys = [k1, k11]
app=x1, number_keys = [k1]
app=x2, number_keys= [k2]
app=x2, number_keys= [k2]
expected result:
app=x1, [k1=3, k11=1]
app=x2, [k2=2]
The following sql output results are out of order.
SELECT
app,
arraySort(x -> x, arrayZip((sumMap(number_keys, arrayResize(CAST([], 'Array(UInt64)'), length(number_keys), 20)) AS x).1, x.2)) AS res
FROM app_log_local
WHERE timestamp > '2023-09-12 08:00:00'
GROUP BY app
Query id: 1da30869-c3b2-4ee3-adc3-288d318d48f8
┌─app────────────────────────────────────┬─res─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ channelz │ [('bytes_received',8660),('bytes_sent',3660),('duration',3660),('response_code',3660)] │
│ cafeteria-sandbox │ [('bytes_received',560),('bytes_sent',460),('duration',460),('response_code',860)] │
│ meta │ [('bytes_received',6100),('bytes_sent',6100),('duration',6100),('response_code',6100)] │
│ order20-adapter │ [('at',5100),('bytes_received',11540),('bytes_sent',11540),('duration',11540),('httpCode',5100),('response_code',11540),('timeCost',5100),('ts',7640)] │
│ gpt-code-manager │ [('bytes_received',5100),('bytes_sent',5100),('duration',5100),('response_code',5700)] │
│ logistics21 │ [('bytes_received',4220),('bytes_sent',4520),('duration',4520),('response_code',4020)]
Activity
[-]how to count by group element of array[/-][+]how to sort by group and count element of array[/+]UnamedRus commentedon Sep 12, 2023
den-crane commentedon Sep 12, 2023
@rfyiamcool please use https://fiddle.clickhouse.com/ for sharing input data