I am having price , volume received every seconds to my tick table , from there i need materialiszed view , where it automatically calculate volume profile for me .Volume profile in the sense I need for unique price it must add up all the volume.I am trying this in clickhouse.
CREATE MATERIALIZED VIEW vp_1min_view
TO vp_1min
AS
SELECT
symbol,
price,
toStartOfMinute(timestamp) AS minute,
SUM(volume) AS total_volume,
COUNT(DISTINCT price) AS trade_count
FROM tick
GROUP BY symbol, price, toStartOfMinute(timestamp)
ORDER BY symbol, minute, price;
Here above I need only single 148 price with columns summed up.But no matter what I try price is not getting unique for that particular minute.I tried all AI tools , and non seems to help.
it could be a bug in group by
or in the wrapper function toStartOfMinute()
or in combination of both.
try date_trunc
see if that makes a difference:
SELECT
symbol,
price,
date_trunc('minute', timestamp) AS minute,
SUM(volume) AS total_volume,
COUNT(DISTINCT price) AS trade_count
FROM tick
GROUP BY symbol, price, date_trunc('minute',timestamp)
ORDER BY symbol, minute, price;