New answers tagged

5

Assuming 2016-04-05 0:27:15 instead of 2016-04-05 1:27:15 in the underlying table, the question would make more sense to me: CREATE TABLE tbl (created_at timestamp, status text); INSERT INTO tbl VALUES ('2016-04-05 00:27:15', 'info') , ('2016-04-05 03:27:15', 'info') , ('2016-04-05 05:27:15', 'warn') , ('2016-04-05 10:27:15', 'info') , ('2016-04-05 ...


4

To answer this, I did the following. (I found the following three threads helpful - 1, 2 and 3. I also found the documentation on generate_series and CROSSTAB here and here respectively to be useful). This should work on 9.1 - not tested, but the documentation indicates that no post-9.1 stuff is being used. Created a table: ntest=# create table ...


1

Use the aggregate FILTER clause in Postgres 9.4+: SELECT count(*) FILTER (WHERE rank = ANY ('{a,b,v}')) AS myvalues , count(*) FILTER (WHERE rank = ANY ('{c,d,j}')) AS yourvalues , count(*) FILTER (WHERE rank = 'e') AS extravalues FROM main; Details and alternatives for older versions: Return counts for multiple ranges in a single ...



Top 50 recent answers are included