我收到此错误:
ERROR: column "errors" does not exist
LINE 11: where errors >= 1
即使我用选择检查了结果。
我正在使用 postgresql 服务器,我有一个名为 log 的表,如下所示:
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)
数据库中有很多行。
这是我的查询
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;
但是当我在没有“where errors>=1”的情况下尝试此查询时,我得到了预期的结果,其中包含 2 列,一个命名日期,另一个命名错误
这是结果
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;
结果:
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