请大神帮忙转换一条SQL语句 [PostgreSQL]
WITH x AS (SELECT date_trunc('minute', happentime) AS min_slice,varname,value FROM 表 where varname='变量名')
SELECT DISTINCT m.min_slice, count(x.min_slice) OVER (ORDER BY m.min_slice) AS running_ct, varname, value FROM (SELECT generate_series(min(min_slice), max(min_slice), '30m') AS min_slice FROM x) m
LEFT JOIN x USING (min_slice) ORDER BY 1