Skip site navigation (1) Skip section navigation (2)

How to use an alias name in the current select

From: Guy Deleeuw <G(dot)De_Leeuw(at)eurofer(dot)be>
To: pgsql-admin(at)postgresql(dot)org
Subject: How to use an alias name in the current select
Date: 2010-03-24 16:42:10
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-admin

I have :
          t_orders_articles.k_id            AS k_id
         ,t_orders_articles.quantity        AS order_qty
         ,(SELECT sum(quantity) FROM t_deliveries_articles WHERE 
article_id = t_orders_articles.k_id) AS delivery_qty
         , (t_orders_articles.quantity - delivery_qty)       AS qty
       FROM t_orders_articles

But it's not working I receive the error :
ERROR : The column delivery_qty does not exist.

How can I make that without having 2 select call ?



pgsql-admin by date

Next:From: Ray StellDate: 2010-03-24 17:10:31
Subject: 8.2.15 pitr/00000001.history
Previous:From: Alvaro HerreraDate: 2010-03-24 03:22:57
Subject: Re: tuning auto vacuum for highly active tables

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group