Обсуждение: Select ... From (Select ...)?

Поиск
Список
Период
Сортировка

Select ... From (Select ...)?

От
"Steven O'Toole"
Дата:
Is there any way to do this kind of query in PGSQL?

SELECT count0, count1 FROM (
SELECT COUNT(*) AS count0
FROM measurement
WHERE responseTime = 0
GROUP BY responseTime
), (
SELECT COUNT(*) AS count1
FROM measurement
WHERE responseTime = 1
GROUP BY responseTime
)
;

Re: Select ... From (Select ...)?

От
Tom Lane
Дата:
"Steven O'Toole" <steven@o2l.com> writes:
> Is there any way to do this kind of query in PGSQL?
> SELECT count0, count1 FROM (
> SELECT COUNT(*) AS count0
> FROM measurement
> WHERE responseTime = 0
> GROUP BY responseTime
> ), (
> SELECT COUNT(*) AS count1
> FROM measurement
> WHERE responseTime = 1
> GROUP BY responseTime
> )
> ;

PG 7.1 supports this ... but note it requires you to adhere to the
letter of the SQL spec: you must provide an alias table name for
each sub-select-in-FROM:

    SELECT ... FROM (SELECT ...) AS foo, ...

The AS word is optional, but the alias "foo" is not.

            regards, tom lane