Re: SQL Question - Using Group By

Поиск
Список
Период
Сортировка
От ksherlock@gmail.com
Тема Re: SQL Question - Using Group By
Дата
Msg-id 1172266961.049030.91440@a75g2000cwd.googlegroups.com
обсуждение исходный текст
Ответ на SQL Question - Using Group By  ("Mike" <akiany@gmail.com>)
Ответы Re: SQL Question - Using Group By  ("Mike" <akiany@gmail.com>)
Re: SQL Question - Using Group By  (Alban Hertroys <alban@magproductions.nl>)
Список pgsql-general
You could use COUNT() in conjunction with NULLIF:

select "Type",
count(nullif("Active", false)) as "Active Count",
count(nullif("Active", true)) as "Inactive Count",
100 * count(nullif("Active", false)) / count(*) as "Active Percent"
from table_name group by "Type"


On Feb 23, 2:50 pm, "Mike" <aki...@gmail.com> wrote:
> Hi,
>
> I have a question about using Group By.
>
> On a table like this:
>
> Type (varchar)     |     Active (boolean)
> --------------------------------------------------------
> Type One           |      False
> Type Two           |      True
> Type One           |      True
> Type Fifty           |      Flase
> Type Two           |      True
>
> Having this table I want a report grouping Types and giving me more
> statistics such as:
>
> Type    |    Active Count    |     Inactive Count    |    Active
> Percent
>
> How do i do that?
>
> I can think of :
>
> select Type from table_name group by Type
>
> But that doesn't give me how many active and inactive each had!
>
> Please help me here understand how to approach this.
>
> Thank you,
> Mike



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

Предыдущее
От: "Mike"
Дата:
Сообщение: SQL Question - Using Group By
Следующее
От: "Robert Haas"
Дата:
Сообщение: Re: complex referential integrity constraints