-- Most popular file latest 30 min

\set TEXT_HTML 2

--explain
select
	hl.sessionid,
	substring('http://' || hostname || path || query from 1 for 80) as "url"
	into temp table foo
from
	httplog hl, 
	hostname hn,
	path p,
	query q
where 
	--hitDateTime > '2004-08-01 18:00'
	hitDateTime > current_timestamp - '120 min'::interval
	and hl.servernameid = hn.hostnameid
	and hl.pathid = p.pathid
	and hl.queryid = q.queryid
	and hl.contenttypeid=(select contenttypeid from contenttype where contenttype='text/html')
	--and hl.contenttypeid = :TEXT_HTML -- text/html
group by
	hn.hostname,
	p.path,
	q.query,
	hl.sessionid
;

select 
	count(sessionID) as "Count",
	url 
from
	foo
group by
	url
order by
	"Count" desc
limit 30
;
