Re: query: "count" each minute between start/end




"Nikolas Tautenhahn" <virtual@xxxxxx> a écrit dans le message de news: f8fhlj$4il$03$1@xxxxxxxxxxxxxxxxxxxx
| Hi,
|
| Michel Cadot wrote:
| >
| > SQL> with cal as
| > 2 ( select to_date('&start','DD/MM/YYYY HH24:MI')+(rownum-1)/1440 tim
| > 3 from dual
| > 4 connect by level <= &duration )
| > 5 select cal.tim, sum(decode(t.c_date,null,0,1)) "nbIn"
| > 6 from cal, t
| > 7 where t.c_date (+) < cal.tim and (t.c_date(+)+duration(+)/86400) >= cal.tim
| > 8 group by cal.tim
| > 9 order by cal.tim
| > 10 /
|
| That was what I had in mind... it is quite slow on real data, but the
| trick with "connect by level" was a great thing to learn - thanks a lot
| for that!
|
| Now if I could just make it a bit more efficient...
| Maybe it would be better to cycle over the data and "create" the minutes
| which are between start and end instead of creating the minutes first
| and searching for matching data afterwards (maybe grouping after the
| minutes)...
|
| Ah well it is not easy, but at least there is one working example :)
|
| Regards,
| N.

It depends if you want each and every minute or only the minutes when
there is someone.
If the former case, you have to first generate the calendar and outer join.

You said it is slow, post your execution plan.

Regards
Michel Cadot


.



Relevant Pages

  • Re: How to see Predicates in xplan display?
    ... Michel Cadot wrote: ... I've been using Sql Developer a little here recently ... | 9 ORDER BY syedoc; ...
    (comp.databases.oracle.server)
  • Re: Reduce To Ranges aggregate function
    ... Michel Cadot wrote: ... | numbers to a reduced form. ... I'm thinking if there were an aggregate function that would ... SQL> select id from t order by id; ...
    (comp.databases.oracle.misc)
  • Re: Aggregation Problem
    ... | I want a query thats shows all rows of the table but has a new ... | Is there an aggregation function that can do this? ... SQL> with ... Michel Cadot ...
    (comp.databases.oracle.misc)
  • Re: Update trigger, detecting missing columns
    ... |> SQL> create table zz; ... |> Michel Cadot ... | var bnd2 VARCHAR2 ... - if B is not given is the set clause then clear B. ...
    (comp.databases.oracle.misc)
  • Re: Update trigger, detecting missing columns
    ... Michel Cadot schrieb: ... |> SQL> create table zz; ... |> SQL> create or replace trigger zz_bu before update on zz for each row ... | var bnd2 VARCHAR2 ...
    (comp.databases.oracle.misc)