Re: [SQL] Need magical advice for counting NOTHING

2009-07-25 Thread Andreas
nha schrieb: Hello, Le 23/07/09 10:23, Glenn Maynard a écrit : On Thu, Jul 23, 2009 at 1:01 AM, Andreas wrote: SELECT user_name, log_type_fk, COUNT(log_type_fk) FROM log JOIN users ON (user_id = user_fk) WHERE (ts IS BETWEEN sometime AND another) GROUP BY user_name, log_type_fk ORD

Re: [SQL] Need magical advice for counting NOTHING

2009-07-24 Thread nha
Hello, Le 23/07/09 10:23, Glenn Maynard a écrit : > On Thu, Jul 23, 2009 at 1:01 AM, Andreas wrote: >> SELECT user_name, log_type_fk, COUNT(log_type_fk) >> FROM log >> JOIN users ON (user_id = user_fk) >> WHERE (ts IS BETWEEN sometime AND another) >> GROUP BY user_name, log_type_fk >> ORDER BY

Re: [SQL] Need magical advice for counting NOTHING

2009-07-23 Thread Glenn Maynard
On Thu, Jul 23, 2009 at 1:01 AM, Andreas wrote: > SELECT user_name, log_type_fk, COUNT(log_type_fk) > FROM log > JOIN users ON (user_id = user_fk) > WHERE (ts IS BETWEEN  sometime  AND   another) > GROUP BY user_name, log_type_fk > ORDER BY user_name, log_type_fk create table users (user_id intege

Re: [SQL] Need magical advice for counting NOTHING

2009-07-23 Thread A. Kretschmer
In response to A. Kretschmer : > test=*# select foo.user_name, foo.log_type, sum(case when log_type_fk is > not null then 1 else 0 end) from (select user_id, user_name, > log_type_id, log_type from users cross join log_type) foo full join log > on ((foo.user_id, foo.log_type_id)=(log.user_fk, log.l

Re: [SQL] Need magical advice for counting NOTHING

2009-07-22 Thread A. Kretschmer
In response to Andreas : > Hi, > The source select counts log-events per user. > All is well when a user has at least one event per log_type in the log > within a given timespan. > If one log_type is missing COUNT() has nothing to count and there is > expectedly no result line that says 0. > BUT

Re: [SQL] Need magical advice for counting NOTHING

2009-07-22 Thread Shane Ambler
Andreas wrote: Hi, The source select counts log-events per user. All is well when a user has at least one event per log_type in the log within a given timespan. If one log_type is missing COUNT() has nothing to count and there is expectedly no result line that says 0. BUT I need this 0-line be

[SQL] Need magical advice for counting NOTHING

2009-07-22 Thread Andreas
Hi, The source select counts log-events per user. All is well when a user has at least one event per log_type in the log within a given timespan. If one log_type is missing COUNT() has nothing to count and there is expectedly no result line that says 0. BUT I need this 0-line because of a cross