OΜ
SELECT
status,
status = 200 as good,
status = 400 as bad,
status = 304 as warning,
status = 302 as error
FROM
(
SELECT
timestamp,
status,
(intDiv(toUInt32(timestamp), 60)) * 1000 AS t,
countIf(status = 200) AS goodStatus,
countIf(status = 400) AS badStatus,
countIf(status = 304) AS warningStatus,
countIf(status = 302) AS errorStatus
FROM access_logs
WHERE ((timestamp >= toDate(1615980933)) AND (timestamp <= toDate(1615998052)))
GROUP BY t
ORDER BY t
)
Текст ошибки:
Code: 215, e.displayText() = DB::Exception: Column `timestamp` is not under aggregate function and not in GROUP BY: While processing timestamp, status, intDiv(toUInt32(timestamp), 60) * 1000 AS t, countIf(status = 200) AS goodStatus, countIf(status = 400) AS badStatus, countIf(status = 304) AS warningStatus, countIf(status = 302) AS errorStatus (version 21.1.2.15 (official build))
Структура:
CREATE TABLE access_logs
(
`request_id` String,
`timestamp` DateTime,
`remote_user` String,
`remote_addr` String,
`scheme` String,
`host` String,
`server_addr` String,
`request_method` String,
`request_uri` String,
`request_length` UInt32,
`request_time` Float64,
`status` UInt16,
`body_bytes_sent` UInt32,
`upstream_addr` String,
`upstream_status` String,
`upstream_response_time` Float64
)
ENGINE = MergeTree
PARTITION BY toDate(timestamp)
ORDER BY (timestamp, host)
TTL timestamp + toIntervalWeek(1)
SETTINGS index_granularity = 8192;