PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Spalte existiert nicht Fehler, auch wenn das Schlüsselwort 'as' verwendet wird

ersetzen Sie where errors >= 1 mit (cast(a.count as decimal) * 100 / b.count)>=1 da es keine Spalte namens Fehler gibt, sondern eine abgeleitete Spalte :

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; 

ODER

Es kann wie oben wie folgt verwendet werden:

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;

innerhalb einer Unterabfrage.