sql >> Base de Datos >  >> RDS >> PostgreSQL

la columna no existe error incluso cuando se usa la palabra clave 'as'

reemplazar where errors >= 1 with (cast(a.count as decimal) * 100 / b.count)>=1 ya que no hay una columna llamada errores sino una columna derivada:

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 (cast(a.count as decimal) * 100 / b.count) >= 1
 order by errors desc; 

O

Se puede usar como arriba como abajo:

select *
  from (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) q
 where errors >= 1
 order by errors desc;

dentro de una subconsulta.