Re: [GENERAL] how to use aggregate functions in this case

2013-08-27 Thread David Johnston
David Johnston wrote > > Janek Sendrowski wrote >> Hi, >> >>   >> >> thanks for all your answers. >> >> I'll have a try with the contains operator and the intrange, but >> before I'd like to know if this would work: >> >>   >> >> CASE WHEN a >= 0 AND a < 25 >> >> CASE WHEN a >= 25 AND

Re: [GENERAL] how to use aggregate functions in this case

2013-08-26 Thread David Johnston
Janek Sendrowski wrote > Hi, > >   > > thanks for all your answers. > > I'll have a try with the contains operator and the intrange, but > before I'd like to know if this would work: > >   > > CASE WHEN a >= 0 AND a < 25 > > CASE WHEN a >= 25 AND a < 50 > >   > > There wouldn't be a

Re: [GENERAL] how to use aggregate functions in this case

2013-08-26 Thread Janek Sendrowski
Hi,   thanks for all your answers. I'll have a try with the contains operator and the intrange, but before I'd like to know if this would work:   CASE WHEN a >= 0 AND a < 25 CASE WHEN a >= 25 AND a < 50   There wouldn't be a double endpoint. I just have to decide which range the endpoint i

Re: [GENERAL] how to use aggregate functions in this case

2013-08-26 Thread David Johnston
BladeOfLight16 wrote > Then again, I guess you don't need a nested query. > > SELECT v_rec1.user, > CASE WIDTH_BUCKET(v_rec_fts.lev, 0, 100, 4) > WHEN 1 THEN '0 to 25' > WHEN 2 THEN '25 to 50' > WHEN 3 THEN '50 to 75' > WHEN 4 THEN '

Re: [GENERAL] how to use aggregate functions in this case

2013-08-25 Thread BladeOfLight16
On Sun, Aug 25, 2013 at 8:36 PM, BladeOfLight16 wrote: > This appears to be some kind of equal interval problem. > > SELECT v_rec1.user, > WIDTH_BUCKET(v_rec_fts.lev, 0, 100, 4) AS bucket > COUNT(*) as count, > FROM v_rec2 > GROUP BY user, bucket; > > (Untested, but this should be

Re: [GENERAL] how to use aggregate functions in this case

2013-08-25 Thread BladeOfLight16
On Sun, Aug 25, 2013 at 5:59 PM, Janek Sendrowski wrote: > SELECT v_rec1.user, > sum(CASE WHEN v_rec_fts.lev BETWEEN 0 AND 25 THEN 1 ELSE 0 END) as > "0 to 25", > sum(CASE WHEN v_rec_fts.lev BETWEEN 25 AND 50 THEN 1 ELSE 0 END) > as "25 to 50", > sum(CASE WHEN v_rec_fts.l

Re: [GENERAL] how to use aggregate functions in this case

2013-08-25 Thread David Johnston
Janek Sendrowski wrote > Sorry, I formulated it wrong. > > My problem is, that I want to count the ranges for every user, but if I > use count(range), it counts the ranges of all users. Assuming your example output is indeed what you desire: SELECT user, '0 to 25'::varchar AS percentage, count

Re: [GENERAL] how to use aggregate functions in this case

2013-08-25 Thread Janek Sendrowski
Sorry, I formulated it wrong. My problem is, that I want to count the ranges for every user, but if I use count(range), it counts the ranges of all users.   Janek Sendrowski

Re: [GENERAL] how to use aggregate functions in this case

2013-08-25 Thread David Johnston
Janek Sendrowski wrote > Hi, > > Thats my code snipped: >   > SELECT  v_rec1.user, >        sum(CASE WHEN v_rec_fts.lev BETWEEN 0 AND 25 THEN 1 ELSE 0 END) as > "0 to 25", >         sum(CASE WHEN v_rec_fts.lev BETWEEN 25 AND 50 THEN 1 ELSE 0 END) > as "25 to 50", > sum(CASE WHEN v_rec_fts

[GENERAL] how to use aggregate functions in this case

2013-08-25 Thread Janek Sendrowski
Hi, Thats my code snipped:   SELECT  v_rec1.user,        sum(CASE WHEN v_rec_fts.lev BETWEEN 0 AND 25 THEN 1 ELSE 0 END) as "0 to 25",         sum(CASE WHEN v_rec_fts.lev BETWEEN 25 AND 50 THEN 1 ELSE 0 END) as "25 to 50", sum(CASE WHEN v_rec_fts.lev BETWEEN 50 AND 100 THEN 1 ELSE 0 END