PostgreSQL
 sql >> Base de données >  >> RDS >> PostgreSQL

la colonne n'existe pas d'erreur même lors de l'utilisation du mot-clé 'as'

remplacer where errors >= 1 avec (cast(a.count as decimal) * 100 / b.count)>=1 puisqu'il n'y a pas de colonne appelée errors mais une colonne dérivée :

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; 

OU

Il peut être utilisé comme ci-dessus comme ci-dessous :

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;

dans une sous-requête.