I have a big table on postgresql and I want to get multiple result sets as an output of a SELECT
query if is it possible ?
My table looks like this:
select * from dns_table
id | dns_name | ip_source | mac_source | query_time
-----+----------------+------------+-------------------+----------------------------
1 | google.com | /10.0.0.1 | 00-00-00-00-00-01 | 2014-05-12 10:03:03.503938
2 | facebook.com | /10.0.0.1 | 00-00-00-00-00-01 | 2014-05-12 10:03:04.567417
3 | google.com | /10.0.0.5 | 00-00-00-00-00-05 | 2014-05-12 10:03:05.372453
4 | youtube.com | /10.0.0.1 | 00-00-00-00-00-01 | 2014-05-12 10:03:05.636633
5 | facebook.com | /10.0.0.5 | 00-00-00-00-00-05 | 2014-05-12 10:03:06.420067
6 | yahoo.com | /10.0.0.1 | 00-00-00-00-00-01 | 2014-05-12 10:03:06.685871
7 | google.com | /10.0.0.6 | 00-00-00-00-00-06 | 2014-05-12 10:03:07.198905
8 | youtube.com | /10.0.0.5 | 00-00-00-00-00-05 | 2014-05-12 10:03:07.524503
9 | wikipedia.org | /10.0.0.1 | 00-00-00-00-00-01 | 2014-05-12 10:03:07.747143
10 | facebook.com | /10.0.0.6 | 00-00-00-00-00-06 | 2014-05-12 10:03:08.287584
11 | yahoo.com | /10.0.0.5 | 00-00-00-00-00-05 | 2014-05-12 10:03:08.572827
...
...
What I want is :
SELECT
count(dns_name) as hits,
dns_name,
to_char(query_time - interval '1 month','YYYY,MM,DD,HH24,MI') as qt
FROM dns_table
where dns_name like '**google.com**'
group by dns_name, qt
order by qt;
hits | dns_name | qt
------+------------+------------------
61 | google.com | 2014,04,12,10,03
40 | google.com | 2014,04,12,15,05
45 | google.com | 2014,04,13,09,34
So I'm wondering if is it possible to replace google.com with a parameter in order to obtain the result set for each dns_name
(google.com
, facebook.com
, yahoo.com
, ...).
Don't hesitate for any questions !