Hi,
I have a dataset that has ranked output with RANK() function used. The dataset is working but in the chart I cannot see the columns - no columns available.
Has anybody tried something like this? Should I do something into the dataset or this type is not supported?
The dataset:
DROP TABLE IF EXISTS web1_tbl;
DROP TABLE IF EXISTS web2_tbl;
CREATE TEMPORARY TABLE web1_tbl AS SELECT *
FROM (
SELECT COALESCE(NULLIFNA(`user`), `srcip`) AS user_src,
SUM(COALESCE(`sentbyte`, 0)+COALESCE(`rcvdbyte`, 0)) AS bandwidth
FROM $log
WHERE $filter
AND `status` IN (' accept' ,' close' )
AND `utmaction`=' passthrough'
GROUP BY user_src
HAVING SUM(COALESCE(`sentbyte`, 0)+COALESCE(`rcvdbyte`, 0))>0
ORDER BY bandwidth DESC
LIMIT 3
) t;
CREATE TEMPORARY TABLE web2_tbl AS SELECT *
FROM(
SELECT TO_TIMESTAMP(`itime`)::timestamp AS time,
TO_CHAR((`duration` || ' second' )::interval, ' HH24:MI:SS' ) AS dur,
COALESCE(NULLIFNA(`user`), `srcip`) AS user_src,
COALESCE(NULLIFNA(ROOT_DOMAIN(`hostname`)),' Unknown Website' )||' (' ||`dstip`||' )' AS website,
COALESCE(NULLIFNA(`catdesc`),' Unknown Category' ) AS web_cat,
SUM(COALESCE(`sentbyte`, 0)+COALESCE(`rcvdbyte`, 0)) AS bandwidth
FROM $log
WHERE $filter
AND `status` IN (' accept' ,' close' )
AND `utmaction`=' passthrough'
GROUP BY time, dur, user_src, srcip, website, web_cat
HAVING SUM(COALESCE(`sentbyte`, 0)+COALESCE(`rcvdbyte`, 0))>0
ORDER BY bandwidth DESC
) t;
SELECT * FROM (
SELECT web2_tbl.time,
web2_tbl.dur,
web2_tbl.user_src,
web2_tbl.website,
web2_tbl.web_cat,
web2_tbl.bandwidth,
RANK() OVER (PARTITION BY web2_tbl.user_src
ORDER BY web2_tbl.bandwidth DESC)
RANK FROM web2_tbl
INNER JOIN web1_tbl ON web2_tbl.user_src=web1_tbl.user_src
)
RANKED WHERE RANK<=10
ORDER BY user_src ASC, bandwidth DESC