Lost with dataset to sort top applications sorted by session count for each destination IP
I am trying to generate a report to show the top applications by session count and the destination IPs.
Essentially I have :
Dataset 1 to show top applications by sessions.
select appid, app, appcat, (case when (utmaction in ('block', 'blocked') or action='deny') then 'Blocked' else 'Allowed' end) as custaction, sum(coalesce(sentbyte, 0)+coalesce(rcvdbyte, 0)) as bandwidth,count(*) as num_session from $log where $filter and logid_to_int(logid) not in (4, 7, 14) and nullifna(app) is not null and policyid != 0 group by appid,app, appcat,custaction order by bandwidth desc
Dataset 2 to show all the destination IPs by application and number of sessions.
select dstip, app, appid, hostname, count(*) as total_num from $log where $filter and logid_to_int(logid) not in (4, 7, 14) group by dstip, app, appid, hostname order by total_num desc
Dataset 2 does not sort the results by the *top* applications like in dataset 1 but rather by the session count, i have tried every SQL statement that can be thought of to do the sorting but i am not an expert when it comes to combining SQL queries.
What i want now is to combine both datasets to actually do a drill down of dataset 1.
Any help please?