Selecting Fields in Union in Subquery

Поиск
Список
Период
Сортировка
От Tom Burns
Тема Selecting Fields in Union in Subquery
Дата
Msg-id 1342216174.12212.YahooMailNeo@web122505.mail.ne1.yahoo.com
обсуждение исходный текст
Ответы Re: Selecting Fields in Union in Subquery  (Bartosz Dmytrak <bdmytrak@gmail.com>)
Список pgsql-novice
Hi All Hope You Can Help,

I have a query that selects from a sub-query:
    select *
    from
    (select g.geo_id as "Id", g.geo_name as "Country", gTo.geo_name as "StateProvence"
    from geo g,geo gTo, geo_assoc ga
    where ga.geo_id = g.geo_id
    and ga.geo_id_to = gTo.geo_id
    and g.geo_id IN (select geo_id from geo where geo_type_id='COUNTRY')
    and g.geo_id = 'USA'
    union
    select g.geo_id as "Id", g.geo_name as "Country", '' as "State/Provence"
    from geo g LEFT OUTER JOIN geo_assoc ga on g.geo_id = ga.geo_id
    where g.geo_type_id='COUNTRY' and ga.geo_id is null
    and g.geo_id = 'USA') as GeoList
    order by 3;

I would like to filter and order by fields returned by the sub-query . For example;
from(select... clause.
The order "order by 3;"works

I can no figure out the syntax for directly addressing fields (for example 'order by StateProvence" or "order by gTo.geo_name" instead of order by 3)
I would like to be able to filter and sort the sub-query in the parent query.

Thanks for any help,

Tom

В списке pgsql-novice по дате отправления:

Предыдущее
От: "ktm@rice.edu"
Дата:
Сообщение: Re: How to apply a regular expression to a select statement
Следующее
От: Ioannis Anagnostopoulos
Дата:
Сообщение: Index slow down insertions...