Re: combine SQL SELECT statements into one

Поиск
Список
Период
Сортировка
От Igor Neyman
Тема Re: combine SQL SELECT statements into one
Дата
Msg-id F4C27E77F7A33E4CA98C19A9DC6722A2057D815E@EXCHANGE.corp.perceptron.com
обсуждение исходный текст
Ответ на Re: combine SQL SELECT statements into one  (Chris.Ellis@shropshire.gov.uk)
Ответы Re: combine SQL SELECT statements into one  (Scott Marlowe <scott.marlowe@gmail.com>)
Re: combine SQL SELECT statements into one  (Chris.Ellis@shropshire.gov.uk)
Список pgsql-general

> -----Original Message-----
> From: Chris.Ellis@shropshire.gov.uk
> [mailto:Chris.Ellis@shropshire.gov.uk]
> Sent: Monday, February 01, 2010 4:08 AM
> To: neilstylz@yahoo.com
> Cc: pgsql-general@postgresql.org
> Subject: Re: combine SQL SELECT statements into one
>
>
> Hi
>
> pgsql-general-owner@postgresql.org wrote on 02/01/2010 07:36:55 AM:
>
> > Good Evening, Good Morning Wherever you are whenever you
> may be reading this.
> >
> >
>         snip
> >
> > count1 |  count2  | count3
> > -------------------------------
> >  2              2              4
> >
> > Can this be done with ONE SQL STATEMENT? touching the
> database only ONE time?
>
> You can do the following:
>
> SELECT
>         (SELECT COUNT(distinct model) FROM inventory WHERE
> modified >= '2010-02-01') AS "COUNT_1",
>        (SELECT COUNT(distinct model) FROM inventory WHERE
> modified >= '2010-01-20') AS "COUNT_2",
>        (SELECT COUNT(distinct model) FROM inventory WHERE
> modified >= '2010-01-01') AS "COUNT_3"
> ;
>
> PostgreSQL allows sub-queries in the select list as long as
> the sub-query returns one column
>
> Job done
>
> > Please let me know.
> >
> > Thanx> :)
> > NEiL
> >
>
> Chris Ellis
>
> **************************************************************
> ****************
>
> If you are not the intended recipient of this email please do
> not send it on
>
> to others, open any attachments or file the email locally.
>
> Please inform the sender of the error and then delete the
> original email.
>
> For more information, please refer to
> http://www.shropshire.gov.uk/privacy.nsf
>
> **************************************************************
> ****************
>
> Help prevent the spread of swine flu. CATCH IT. BIN IT. KILL IT.
>
> **************************************************************
> ****************
>

Original poster asked for the sql that will touch inventory table only
once.

Your statement (with 3 subqueries) will do it 3 times.

Igor Neyman

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

Предыдущее
От: Andreas Kretschmer
Дата:
Сообщение: Re: How Copy from a view to CSV file
Следующее
От: frank joerdens
Дата:
Сообщение: Locking referenced table when creating and dropping tables with foreign key constraints