Re: [SQL] SQL problem with aggregate functions.

2002-07-22 Thread Hubert depesz Lubaczewski
On Tue, Jul 09, 2002 at 10:36:17AM +0200, David BOURIAUD wrote: > Field group | count of D | count of R | count of X. if you want this that way, i suggest using subselects. like: select distinct field_group, (select count(*) from table t2 where t2.field_group = t1.field_group and

Re: [SQL] SQL problem with aggregate functions.

2002-07-12 Thread Jean-Luc Lachance
What is wrong with: select field_group, sum( case when f1 = 'D' then cnt else 0 end) as D_COUNT, sum( case when f1 = 'R' then cnt else 0 end) as R_COUNT, sum( case when f1 = 'X' then cnt else 0 end) as X_COUNT from (select field_group, f1, count (*) as cnt from tab group by field_group, f1) a

Re: [SQL] SQL problem with aggregate functions.

2002-07-11 Thread Loyd Goodbar
I would suggest something like select sum(case when f1 = 'D' then 1 else 0 end) as D_COUNT, sum(case when f1 = 'R' then 1 else 0 end) as R_COUNT, sum(case when f1 = 'X' then 1 else 0 end) as X_COUNT from tab where f1 in ('D','R','X') Not sure what the "field group" represents. HTH, Loyd On Thu

Re: [SQL] SQL problem with aggregate functions.

2002-07-11 Thread Christoph Haller
> > I've got a table in which there is a field that can have one amongst 3 > possible values : D, R, X. Is it possible to get in one query the count of > this different values.Please, note that I don't want to have a querry like > this : > "select count (*) from tab group by f1;", cause i want