I get this error:
ERROR: column "errors" does not exist
LINE 11: where errors >= 1
even that i checked the result with select.
I'm using postgresql server, i have a table named log like the following:
Column | Type | Modifiers
--------+--------------------------+--------------------------------------------------
path | text |
ip | inet |
method | text |
status | text |
time | timestamp with time zone | default now()
id | integer | not null default nextval('log_id_seq'::regclass)
there are lots of lines in the db.
here is my query
select
a.date,
(cast(a.count as decimal) * 100 / b.count) as errors
from (
select date(time) as date, count(status) from log
where status!='200 OK'
group by date
order by date asc
) as a
join (
select date(time) as date, count(status)
from log
group by date
order by date asc
) as b on a.date=b.date
where errors >= 1
order by errors desc;
but when I try this query without the 'where errors>=1', I got the expected result with 2 columns one named date and another named errors
here is the result
select
a.date,
(cast(a.count as decimal) * 100 / b.count) as errors
from (
select date(time) as date, count(status) from log
where status!='200 OK'
group by date
order by date asc
) as a
join (
select date(time) as date, count(status)
from log
group by date
order by date asc
) as b on a.date=b.date
order by errors desc;
Result:
date | errors
------------+------------------------
2016-07-17 | 2.2626862468027260
2016-07-19 | 0.78242171265427079381
2016-07-24 | 0.78221415607985480944
2016-07-05 | 0.77493816982687551525
2016-07-06 | 0.76678716179209113813