Query - weight delivered each day

Hi all.
I'm currently working at a query to calculate the weight delivered each day. My thougt is to first calculate from DLN1 table and then subtract from RDN1 table. Deliveries minus returns.
I can easily create these queries as stand alone queries, but I would need some help combining them into one query. I'm thinking coulmns like this; A = date, B = weight deliveries, C = weight returns, D = B minus C
Any takers?
Thanks and regards.
Runar Wigestrand.

Hi!
Check this ....
Declare @FromDate Datetime
Declare @ToDate Datetime
Set @FromDate = (Select min(s0.Docdate) from ODLN S0 where S0.Docdate >='[%0]')
Set @ToDate = (Select max(s1.Docdate) from ODLN S1 where S1.Docdate <='[%1]')
Select
a.Docdate,sum(a.DW) as [Delivery Weight],sum(a.RW) as [Return Weight],
sum(a.DW)-sum(a.RW) as [Total Weight] from (
SELECT T1.[DocDate], SUM(cast(T0.[Weight1] as int)) as DW,0 as RW
FROM DLN1 T0 inner join ODLN T1
on T0.DocEntry = T1.DocEntry
WHERE
T1.DocDate between Convert(Char(10),@FromDate) and Convert(char(10),@ToDate)
Group by T1.[DocDate]
Union all
SELECT T1.[DocDate], 0 as DW,SUM(cast(T0.[Weight1] as int)) as RW
FROM RDN1 T0 inner join ORDN T1
on T0.DocEntry = T1.DocEntry
WHERE
T1.DocDate between Convert(Char(10),@FromDate) and Convert(char(10),@ToDate)
Group by T1.[DocDate] )a
Group By
a.Docdate

Similar Messages

  • Query to get a value for each day in a month

    Hi All,
    I'm needing a query (preferably without a loop or function) that can get a number representing each day of a given month.
    For example for the month of February, the result would be 1,2,3,....28
    Surely this can be done?
    Thanks!

    SQL> with a as (
      2  select trunc(sysdate,'Month') mon from dual)
      3  SELECT mon + LEVEL - 1 AS dates
      4  FROM a
      5  CONNECT BY LEVEL <= ADD_MONTHS (mon, 1)  - mon;
    DATES
    01-FEB-11
    02-FEB-11
    03-FEB-11
    04-FEB-11
    05-FEB-11
    06-FEB-11
    07-FEB-11
    08-FEB-11
    09-FEB-11
    10-FEB-11
    11-FEB-11
    DATES
    12-FEB-11
    13-FEB-11
    14-FEB-11
    15-FEB-11
    16-FEB-11
    17-FEB-11
    18-FEB-11
    19-FEB-11
    20-FEB-11
    21-FEB-11
    22-FEB-11
    DATES
    23-FEB-11
    24-FEB-11
    25-FEB-11
    26-FEB-11
    27-FEB-11
    28-FEB-11
    28 rows selected.or if u want it in one query,Then
    SQL> SELECT trunc(sysdate,'Month') + LEVEL - 1 AS dates
      2  FROM dual
      3  CONNECT BY LEVEL <= ADD_MONTHS (trunc(sysdate,'Month'), 1)  - trunc(sysdate,'Month');
    DATES
    01-FEB-11
    02-FEB-11
    03-FEB-11
    04-FEB-11
    05-FEB-11
    06-FEB-11
    07-FEB-11
    08-FEB-11
    09-FEB-11
    10-FEB-11
    11-FEB-11
    DATES
    12-FEB-11
    13-FEB-11
    14-FEB-11
    15-FEB-11
    16-FEB-11
    17-FEB-11
    18-FEB-11
    19-FEB-11
    20-FEB-11
    21-FEB-11
    22-FEB-11
    DATES
    23-FEB-11
    24-FEB-11
    25-FEB-11
    26-FEB-11
    27-FEB-11
    28-FEB-11
    28 rows selected.
    SQL> Regards
    Umesh

  • I need a query that selects the amount of records for each day in a table.

    I need a query that selects the amount of records for each
    day in a table.
    Eg the result would be:
    date 1 14
    date 2 3
    etc
    Any ideas?

    sorted:
    SELECT count([commentID]),convert(varchar, dateAdded, 112)
    FROM COMMENTSgroup by convert(varchar, dateAdded,
    112)

  • Metadata query to extract each session run duration for last 10 Runs (10 days if daily scheduled)

    Hi all, Please can anybody help me with metadata query to extract all the sessions run duration information (start time and end time, run duration)in each workflow for last 10days.I dont have access to metadata repository so need exact query so that i can raise a request to admin team(he needs exact query). I know that we can get information from REP_WFLOW_RUN , but i dont know the table structure so please provide full query. Thanks,Ravi kumar

    Hi all, Please help me with metadata query to extract each session RUN_DURTION, Start Time, end time for last 10 runs of each session at a workflow level. I know we can get information from REP_WFLOW_RUN table but i dont know table strucure and I dont have access to Repository database and we need an exact query to raise it to admin team. so please provide me an exact query.   Thanks

  • Query help to Get day wise count

    I have a table: Table_Sample with two columns:
    Date_Time_Field - Timestamp;
    Request_Type - Number;
    The insert statement for the table is as follows:
    -- INSERTING into TABLE_SAMPLE1
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('01-JUL-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),1);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('01-JUL-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),2);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('12-JUL-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),2);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('01-AUG-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),7);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('21-SEP-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),2);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('03-OCT-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),1);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('13-OCT-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),1);
    Insert into TABLE_SAMPLE1 (DATE_TIME_FIELD,REQUEST_TYPE) values (to_timestamp('04-NOV-07 12.00.09.000000000 PM','DD-MON-RR HH.MI.SS.FF AM'),7);
    I want to get the count of request_Type on each day..In this table some dates are missing, but i want to fill the count of request_Type on those days as 0.
    i.e., expected out put is
    Date          Request_Type              Count(Request_Type)
    01-JUL-07         1                             1
    01-JUL-07         2                             1
    01-JUL-07         7                             0
    02-JUL-07         1                             0
    02-JUL-07         2                             0
    02-JUL-07         7                             0
    03-JUL-07         1                             0
    03-JUL-07         2                             0
    03-JUL-07         7                             0
    11-JUL-07         1                             0
    11-JUL-07         2                             1
    11-JUL-07         7                             0
    :How can i form the query for this

    Using Data Densification for Reporting (available on 10g and above):
    SQL> with Request_Types AS (
      2    select distinct request_type from TABLE_SAMPLE1
      3  ),
      4  Calendar as (
      5    select date '2007-07-01' + level - 1 as date_time
      6    from dual
      7    connect by level <= 13
      8  )
      9  select c.date_time, rt.request_type, sum(case when ts.rowid is null then 0 else 1 end) as cnt
    10  from Request_Types rt
    11    join Calendar c on 1=1
    12    left outer join Table_Sample1 ts partition by (date_time_field, request_type)
    13    on ts.request_type = rt.request_type
    14       and trunc(ts.date_time_field) = c.date_time
    15  group by c.date_time, rt.request_type
    16  order by c.date_time, rt.request_type
    17  ;
    DATE_TIME  REQUEST_TYPE        CNT
    01.07.2007            1          1
    01.07.2007            2          1
    01.07.2007            7          0
    02.07.2007            1          0
    02.07.2007            2          0
    02.07.2007            7          0
    03.07.2007            1          0
    03.07.2007            2          0
    03.07.2007            7          0
    04.07.2007            1          0
    04.07.2007            2          0
    04.07.2007            7          0
    05.07.2007            1          0
    05.07.2007            2          0
    05.07.2007            7          0
    06.07.2007            1          0
    06.07.2007            2          0
    06.07.2007            7          0
    07.07.2007            1          0
    07.07.2007            2          0
    07.07.2007            7          0
    08.07.2007            1          0
    08.07.2007            2          0
    08.07.2007            7          0
    09.07.2007            1          0
    09.07.2007            2          0
    09.07.2007            7          0
    10.07.2007            1          0
    10.07.2007            2          0
    10.07.2007            7          0
    11.07.2007            1          0
    11.07.2007            2          0
    11.07.2007            7          0
    12.07.2007            1          0
    12.07.2007            2          1
    12.07.2007            7          0
    13.07.2007            1          0
    13.07.2007            2          0
    13.07.2007            7          0
    39 rows selected.Regards,
    Dima

  • SQL help: return number of records for each day of last month.

    Hi: I have records in the database with a field in the table which contains the Unix epoch time for each record. Letz say the Table name is ED and the field utime contains the Unix epoch time.
    Is there a way to get a count of number of records for each day of the last one month? Essentially I want a query which returns a list of count (number of records for each day) with the utime field containing the Unix epoch time. If a particular day does not have any records I want the query to return 0 for that day. I have no clue where to start. Would I need another table which has the list of days?
    Thanks
    Ray

    Peter: thanks. That helps but not completely.
    When I run the query to include only records for July using a statement such as following
    ============
    SELECT /*+ FIRST_ROWS */ COUNT(ED.UTIMESTAMP), TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD') AS DATA
    FROM EVENT_DATA ED
    WHERE AGENT_ID = 160
    AND (TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY')+(ED.UTIMESTAMP/86400)), 'MM/YYYY') = TO_CHAR(SYSDATE-15, 'MM/YYYY'))
    GROUP BY TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD')
    ORDER BY TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD');
    =============
    I get the following
    COUNT(ED.UTIMESTAMP) DATA
    1 07/20
    1 07/21
    1 07/24
    2 07/25
    2 07/27
    2 07/28
    2 07/29
    1 07/30
    2 07/31
    Some dates donot have any records and so no output. Is there a way to show the missing dates with a COUNT value = 0?
    Thanks
    Ray

  • Count for each day

    Hi
    I have a query ,it gives total count of month
    select count(*) from w_srvreq_d where status='Closed' and trunc(close_dt)>'01-may-2003' AND trunc(close_dt)<='31-may-2003'
    COUNT(*)
    82
    I want count for each day
    ex
    date count
    1/5/03 1
    2/5/03 2
    31/5/03 12
    Regards
    Mohan

    Hi
    select count(*) from w_srvreq_d where status='Closed' and trunc(close_dt)>'01-may-2003' AND trunc(close_dt)<='31-may-2003'
    COUNT(*)
    82
    My scnerio is want to join w_day_d and w_srvreq_d dimension and populate in to fact table .This below query populate the data in bt_fault_snapshot_f table,But i want count for each day
    date count sr_cat_type_cd x_bt_current_queue
    1/5/03 1 complaint unspecifie
    2/5/03 2 Fault unspecified
    SELECT dlr.sr_cat_type_cd,
    dlr.x_bt_current_queue,dlr.x_bt_line_of_business ,
    day.snapshot_date AS snapshot_date FROM
    ( SELECT w_day_d.day_dt AS snapshot_date
    FROM (SELECT to_date(nvl(max(date_wid),'20030531'),'yyyymmdd')+1
    AS snapshot_date
         FROM bt_fault_snapshot_f) f ,
         w_day_d , (SELECT CASE WHEN to_number(to_char(sysdate,'hh24')) <18 THEN trunc(sysdate - 1)
                        ELSE trunc(sysdate)
                                       END AS lastdate FROM dual) currdate
                                            WHERE w_day_d.day_dt >= f.snapshot_date
                                            AND w_day_d.day_dt <= currdate.lastdate) day
                                                 , ( SELECT DISTINCT sr_cat_type_cd,x_bt_current_queue,x_bt_line_of_business
                                                      FROM w_srvreq_d) dlr
    Regards
    Mrao

  • Using pl/sql function for each day between two dates.

    Hi,
    create TABLE EMP(
    ID_EMP NUMBER,
    DT_FROM DATE,
    DT_TO DATE,
    CREATE_DATE DATE);
    into EMP(ID_EMP, DT_FROM, DT_TO, CREATE_DATE)
    Values(100, TO_DATE('07/01/2008 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/30/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),TO_DATE('05/08/2009 14:11:21', 'MM/DD/YYYY HH24:MI:SS'));
    I have a function called  elig_pay_dates(date p_date), which returns the code for  person payment eligibility for a particular date. For paid dates it's 'P' and for unpaid dates it's 'N'.
    How can I check this function between two dates for each day. Example : 07/01/2008 to 04/30/2010.
    By using this function with select I needs to display the dates when there is a change in status.
    I am expecting data in following manner from above logic(this is example):
    07/01/2008 --- 07/01/2009 ---'P'
    07/02/2009 -- 07/25/2009 ----'N'
    07/26/2009 -- 01/01/2010 ---'P'
    01/02/2010 -- 01/13/2010 --'N'
    01/14/2010 -- 01/18/2010 --'P'
    01/19/2010 -- 04/30/2010 -- 'N'
    I thought of looping for each day date but that seems to be expensive for online application. Is there any way that I can achieve this requirement with sql query ?
    Thanks for your help,

    Certainly not the best way to code the requirement, but it does achieve the result you are looking for in a fairly quick time
    create or replace
    function test_ret_paid_unpaid (p_date in date)
    return varchar2
    is
      v_ret     varchar2(1);
    begin
      if ( (p_date between to_date('07/02/2009', 'MM/DD/YYYY') and to_date('07/25/2009', 'MM/DD/YYYY') ) or
           (p_date between to_date('01/02/2010', 'MM/DD/YYYY') and to_date('01/13/2010', 'MM/DD/YYYY') ) or
           (p_date between to_date('01/19/2010', 'MM/DD/YYYY') and to_date('04/30/2010', 'MM/DD/YYYY') )
        then v_ret := 'N';
      else
        v_ret := 'Y';
      end if;
      return v_ret;
    end;
    Wrote file afiedt.buf
      1  with get_paid_unpaid as
      2  (
      3    select dt_from start_date, dt_to end_date, dt_from + level - 1 curr_date, test_ret_paid_unpaid(dt_from + level - 1) paid_unpaid,
      4           row_number() over (order by dt_from + level - 1) rn_start,
      5           row_number() over (order by dt_from + level - 1 desc) rn_end
      6      from test_emp
      7    connect by level <= dt_to - dt_from + 1
      8  ),
      9  get_stop_date as
    10  (
    11  select start_date init_date, end_date, curr_date, paid_unpaid,
    12         case when paid_unpaid != lag(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
    13          then curr_date
    14          else null
    15         end start_date,
    16         case when paid_unpaid != lead(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
    17          then curr_date
    18          else null
    19         end stop_date
    20    from get_paid_unpaid
    21  )
    22  select period, paid_unpaid
    23    from (
    24  select init_date, curr_date, start_date, end_date, stop_date,
    25         case when paid_unpaid = lead(paid_unpaid) over (order by curr_date)
    26                then nvl(start_date, init_date) || ' - ' || lead(stop_date, 1, end_date) over (order by curr_date)
    27              else null
    28         end period,
    29         paid_unpaid
    30    from get_stop_date
    31   where stop_date is not null or start_date is not null
    32         )
    33*  where period is not null
    12:06:10 SQL> /
    PERIOD                                             PAID_UNPAID
    01-JUL-08 - 01-JUL-09                              Y
    02-JUL-09 - 25-JUL-09                              N
    26-JUL-09 - 01-JAN-10                              Y
    02-JAN-10 - 13-JAN-10                              N
    14-JAN-10 - 18-JAN-10                              Y
    19-JAN-10 - 30-APR-10                              N
    6 rows selected.
    Elapsed: 00:00:00.35

  • Forecast by each day wise

    Hi,
    I got a requirement to do a forecast on the stock values.
    I have created a Real-Time InfoCube  in which the daily stock Issues and Receipt values are update from the Stock InfoCube  which are actual Values.
    I need to create a Ready-input query doing forecast values based on each day wise of the current month.
    The business case is..assume that today date is 10th of the current month.
    The report should display the actual values from 1 - 10th  and from 11 to last day of the current month it need to be ready-input query to enter the values.
    How to get the each day as column of the current month and how do we restrict the actual and forecast values at each  column.
    Please advice how to meet the requirement.
    Regards
    Jagannadha Raju

    Hi David,
    Thanks for the reply and for your time...
    i want to explain in little bit.
    My stock cube contains the data only upto day (10th). if i put cal day in the column it is display the only upto 10th day. But it should display the columns from 11 to 31 as input query also.
    Please advice on this... even if we don't have data also how would we display all the days as columns.
    Regards
    Jagannadha Raju

  • Max date in each day

    Hi
    How can I to get the max Date in each day in data below , I must to do in unique query
    select to_date('1/6/2010 06:29:04','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:29:04','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:28:03','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:27:58','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:27:57','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:27:57','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:27:52','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:27:45','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:12:48','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:12:43','dd/mm/yyyy hh24:mi:ss')  DATA  from dual union                    
    select to_date('1/6/2010 06:12:43','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:12:42','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('1/6/2010 06:09:53','dd/mm/yyyy hh24:mi:ss') DATA  from dual UNION    
    select to_date('31/05/2010 06:39:04','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:38:04','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:37:03','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:37:02','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:36:57','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:36:56','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:27:52','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:27:45','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:12:48','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:12:43','dd/mm/yyyy hh24:mi:ss')  DATA  from dual union
    select to_date('31/05/2010 06:12:43','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:12:42','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA  from dual union
    select to_date('31/05/2010 06:09:53','dd/mm/yyyy hh24:mi:ss') DATA  from dual
    ORDER BY 1 DESCUsing Oracle 9.2.02
    TIA

    Also possible if you need all the days bettween your first and last day.
    with tab as (
        select to_date('1/6/2010 06:29:04','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:29:04','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:28:03','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:27:58','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:27:57','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:27:57','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:27:52','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:27:45','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:12:48','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:12:43','dd/mm/yyyy hh24:mi:ss')  DATA  from dual union    all                 
        select to_date('1/6/2010 06:12:43','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:12:42','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('1/6/2010 06:09:53','dd/mm/yyyy hh24:mi:ss') DATA  from dual UNION     all
        select to_date('31/05/2010 06:39:04','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:38:04','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:37:03','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:37:02','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:36:57','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:36:56','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:27:52','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:27:45','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:12:48','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:12:43','dd/mm/yyyy hh24:mi:ss')  DATA  from dual union  all
        select to_date('31/05/2010 06:12:43','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:12:42','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('31/05/2010 06:09:53','dd/mm/yyyy hh24:mi:ss') DATA  from dual union all
        select to_date('28/05/2010 02:09:53','dd/mm/yyyy hh24:mi:ss') DATA  from dual
      ,maxmin as (select trunc(min(data)) mindat, trunc(max(data)) maxdat, trunc(max(data))-trunc(min(data))+1 no_of_days from tab)
      ,days as (select rownum + (select mm2.mindat from maxmin mm2) - 1 dy
              from all_objects ao
              where rownum <= (select mm1.no_of_days from maxmin mm1))
    select d.dy, (select max(data) from tab where trunc(data) = d.dy) max_time
    from days d
    dy                max_time
    28.05.10 00:00:00     28.05.10 02:09:53
    29.05.10 00:00:00     
    30.05.10 00:00:00     
    31.05.10 00:00:00     31.05.10 06:39:04
    01.06.10 00:00:00     01.06.10 06:29:04

  • Select last value for each day from table

    Hi!
    I have a table that stores several measures for each day. I need two queries against this table and I am not quite sure how to write them.
    The table stores these lines (sample data)
    *DateCol1                 Value       Database*
    27.09.2009 12:00:00       100           DB1
    27.09.2009 20:00:00       150           DB1
    27.09.2009 12:00:00       1000          DB2
    27.09.2009 20:00:00       1100          DB2
    28.09.2009 12:00:00       200           DB1
    28.09.2009 20:00:00       220           DB1
    28.09.2009 12:00:00       1500          DB2
    28.09.2009 20:00:00       2000          DB2Explanation of data in the sample table:
    We measure the size of the data files belonging to each database one or more times each day. The value column shows the size of the database files for each database at a given time (European format for date in DateCol1).
    What I need:
    Query 1:
    The query should return the latest measurement for each day and database. Like this:
    *DateCol1       Value      Database*
    27.09.2009        150          DB1
    27.09.2009       1100          DB2
    28.09.2009        220          DB1
    28.09.2009       2000          DB2Query 2:
    The query should return the average measurement for each day and database. Like this:
    *DateCol1       Value      Database*
    27.09.2009       125          DB1
    27.09.2009      1050          DB2
    28.09.2009       210          DB1
    28.09.2009      1750          DB2Could someone please help me to write these two queries?
    Please let me know if you need further information.
    Edited by: user7066552 on Sep 29, 2009 10:17 AM
    Edited by: user7066552 on Sep 29, 2009 10:17 AM

    For first query you can use analytic function and solve it.
    with t
    as
    select to_date('27.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss') dt,       100 val,           'DB1' db from dual union all
    select to_date('27.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       150,           'DB1' from dual union all
    select to_date('27.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1000,          'DB2' from dual union all
    select to_date('27.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1100,          'DB2' from dual union all
    select to_date('28.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       200,           'DB1' from dual union all
    select to_date('28.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       220,           'DB1' from dual union all
    select to_date('28.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1500,          'DB2' from dual union all
    select to_date('28.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       2000,          'DB2' from dual
    select dt, val, db
      from (
    select row_number() over(partition by trunc(dt), db order by dt) rno,
           count(*) over(partition by trunc(dt), db) cnt,
           t.*
      from t)
    where rno = cntFor second you can just group by
    with t
    as
    select to_date('27.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss') dt,       100 val,           'DB1' db from dual union all
    select to_date('27.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       150,           'DB1' from dual union all
    select to_date('27.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1000,          'DB2' from dual union all
    select to_date('27.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1100,          'DB2' from dual union all
    select to_date('28.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       200,           'DB1' from dual union all
    select to_date('28.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       220,           'DB1' from dual union all
    select to_date('28.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1500,          'DB2' from dual union all
    select to_date('28.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       2000,          'DB2' from dual
    select trunc(dt) dt, avg(val) val, db
      from t
    group by trunc(dt), db
    order by trunc(dt)

  • 'Average Weighted with Calendar Days' in Exception Aggregation

    Dear specialists,
    I have created a query with a lot of calculated keyfigures.
    One of my calculated keyfigures shows percentage values.
    When I select a calendar day, my report shows correct results
    for the percentage values.
    But when I execute the report without selecting a calendar day,
    I get strange results like 3,21 % instead of 97,49 %.
    There is a new functionality with version 7.0, where we can set
    Aggregation properties like 'Average Weighted with Calendar Days' .
    But when I select this with Ref. characteristic 'calendar day',
    my report does not show any value or any result.
    Are there any other properties to set in Aggregation or Calculations.
    Please give me more information about this issue
    regards Osman Akuzun

    Hi,
           When you define an Exception aggregation on number of work days. There might be some reference characteristic defined in your Bex.
    For exmaple, take a scenario like below. Your BW data is like below
    0Employee           StockIssued
    XXX                            50                                
    XXX                            10              
    YYY                           20              
    YYY                            30             
    YYY                            40             
    ZZZ                            50              
    ZZZ                            100            
    ZZZ                            30              
    Suppose the first row which has values like XXX and 50 is not a working day and remaining all are working days then the exception aggregation applied using AV2 on the characteristic  0Employee will be caluclated in your Report as below
    For XXX, it will       10/1 = 10 (because only 1 working day for the employee XXX)
    For YYY, it will       90/3 = 30 (because all  3  are working days for the employee YYY)
    For ZZZ, it will       180/3 = 60 (because  all  3  are working days for the employee ZZZ)
    This is how the exception aggregation works. Try to see the similar kind of example in your system and try to relate in the same lines explained by me. You can understand.
    Regards
    Sunil

  • Health App Stats Resetting Each Day

    I got the iPhone 6 the day it was released.  I immediately started using the new Health app.  I added the basics, birthday, age, sex, weight, and I added the "Steps" and "Walking + Running Distance" to the dashbaord.  I notice they automatically started tracking my steps.  So I went for a jog, it tracked that also.  Awesome, so far so good.  But the next day it was all gone.  It doesn't matter if I select "Day / Week / Month / Year" at the top top, the stats are always the same, the only show the current day.  I've checked each day since I've got the phone, each day it seems to start over.  Why is all the previous data disappearing?  Thanks!

    http://apple.stackexchange.com/questions/146827/ios-8-health-app-stats-resetting -each-day

  • HT3728 My Time Capsule won't allow me to access my home network each day (intermittently) between about 1000-1800. My modem is working properly, and I can get on-line by hooking my computer straight to my modem, so I know it's the Time Capsule at fault. I

    My Time Capsule won't allow me to access my home wireless network for several hours each day -- usually between 1000-1830 or so. My modem is working correctly and I can still get on-line by going straight from my computer (MacBook Pro) to the Ethernet port. It must be the Time Capsule -- any ideas?

    Any ideas?
    Wireless Interference
    Might be caused by a cordless phone in the vicinity. To give you an example, my neighbor.....across the street...used to be able to literally crash my wireless network if he was in his front yard talking on his cordless phone.
    I discovered this by accident one day after spending weeks trying figure out why my network would crash at random times.
    Other possibilities include a wireless security/camera system near you
    Still other things might be an amateur ham radio operator....which should not interfere....but again from experience, I know that this can occur.
    Yet another possibility is another wireless network near you that is being turned on and off at random times. Some users power up their modem/router only when they want to do so and leave it off otherwise.
    Some general rules to help avoid interference:
    Move any cordless phones that you might have as far away as possible from the Time Capsule and/or your computer(s)
    Avoid placing other electronic devices....computer, television, amplifier, satellite receiver, etc. near the Time Capsule and/or your computer(s)
    Avoid metal surfaces near the Time Capsule and/or your computers
    Elevate the Time Capsule as much as possible. Think of it as a water sprinkler....you want to get the room as wet as possible
    Experiment with different wireless channels on the Time Capsule. To do this:
    Open AirPort Utility
    Click on the Time Capsule
    Click Edit
    Click the Wireless tab
    Click Wireless Options
    Start with Channel 11 on the 2.4 GHz band and work your way down
    It is unlikely that you are picking up interference on the 5 GHz band since there are.....for now at least.....far fewer networks using this frequency.

  • How to enter a new Date and Time each day in a Numbers Spreadsheet...

    Hi... I have finally decided to move away from Excel and really give Numbers a shot... I have an application where each day I first enter the current date and time into a particular cell of a new row and then I enter some data in cells adjacent (in the same row) as that entered date-time. Then the next day I want to again enter the (new) current date and time and add more data next to that new date-time and so forth day after day... You can't use something as simple as =NOW() because then everyday, ALL of the date-times would change to the current time... Nope, now what I want... I just want to be able to EASILY and QUICKLY enter the current date-time value in one call and then have that specific value stay there forever... In Excel, this is accomplished with the keyboard shortcuts of
    <cntl> followed by a semicolon (;) for the date
    then enter a single space (for separation of date versus time) followed last by
    <command> followed again by a semicolon...
    So all together that is,
    <cntl><;><sp><command><;>
    and that puts something like
    4/10/2010 9:49:00 AM
    in a single cell...
    That's what I now want to be able to do in Numbers...
    How do I do that??? Do I use the menubar item "Insert Date and Time" and if so, how exactly do I get the current time to show up in the chosen cell??? With formatting??? Is there a keyboard shortcut method like the one I mentioned that works for Excel?? I've perused the manual and though I found lots on date-time, I didn't see how to do specifically what I want to do... I likely just missed it as surely it must be easy to do...
    Any feedback would be much appreciated... thanks... bob...

    Badunit wrote:
    The result of running that script is "UI Enabled = TRUE".
    I have cells named by the header values.
    This may be the problem.
    The script is an old one which deciphered only the letter+digit cell references.
    Here is a new version which works with every kind of cell reference.
    --[SCRIPT insertDateTime]
    Enregistrer le script en tant que Script : insertDateTime.scpt
    déplacer l'application créée dans le dossier
    <VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
    Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
    Placez le curseur dans la cellule qui doit recevoir la date_heure
    menu Scripts > Numbers > insertDateTime
    La cellule pointée reçoit la date_heure.
    L'aide du Finder explique:
    L'Utilitaire AppleScript permet d'activer le Menu des scripts :
    Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case "Afficher le menu des scripts dans la barre de menus".
    +++++++
    Save the script as a Script : insertDateTime.scpt
    Move the newly created application into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
    Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
    Put the cursor in the cell which must receive the date_time.
    menu Scripts > Numbers > insertDateTime
    The pointed cell receives the current date_time.
    The Finder's Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the "Show Script Menu in menu bar" checkbox.
    Yvan KOENIG (VALLAURIS, France)
    2009/03/01
    2010/04/11 is now able to treat every kind of cell references
    property theApp : "Numbers"
    --=====
    on run
    set {dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
    my doYourDuty(colNum1, rowNum1, tName, sName, dName)
    end run
    --=====
    on doYourDuty(c, r, t, s, d) (*
    c = columnIndex
    r = rowIndex
    t = table's name
    s = sheet's name
    d = document's name *)
    local cdt
    set cdt to my cleanThisDate(current date) (* the new date_time as a clean date_time *)
    tell application "Numbers" to tell document d to tell sheet s to tell table t
    set value of cell r of column c to cdt as text
    end tell -- application …
    end doYourDuty
    --=====
    on cleanThisDate(dt)
    (* ugly code but once I got date_time with milliseconds so if necessary, I drop them *)
    local l
    set l to my decoupe(dt as text, ":")
    if (count of l) > 3 then set dt to date (my recolle(items 1 thru 3 of l, ":"))
    return dt
    end cleanThisDate
    --=====
    on getSelParams()
    local r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2
    set {d_Name, s_Name, t_Name, r_Name} to my getSelection()
    if r_Name is missing value then
    if my parleAnglais() then
    error "No selected cells"
    else
    error "Il n'y a pas de cellule sélectionnée !"
    end if
    end if
    set two_Names to my decoupe(r_Name, ":")
    set {row_Num1, col_Num1} to my decipher(item 1 of two_Names, d_Name, s_Name, t_Name)
    if item 2 of two_Names = item 1 of two_Names then
    set {row_Num2, col_Num2} to {row_Num1, col_Num1}
    else
    set {row_Num2, col_Num2} to my decipher(item 2 of two_Names, d_Name, s_Name, t_Name)
    end if
    return {d_Name, s_Name, t_Name, r_Name, row_Num1, col_Num1, row_Num2, col_Num2}
    end getSelParams
    --=====
    set {rowNumber, columnNumber} to my decipher(cellRef,docName,sheetName,tableName)
    apply to named row or named column !
    on decipher(n, d, s, t)
    tell application "Numbers" to tell document d to tell sheet s to tell table t to return {address of row of cell n, address of column of cell n}
    end decipher
    --=====
    set { d_Name, s_Name, t_Name, r_Name} to my getSelection()
    on getSelection()
    local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
    tell application "Numbers" to tell document 1
    repeat with i from 1 to the count of sheets
    tell sheet i
    set x to the count of tables
    if x > 0 then
    repeat with y from 1 to x
    try
    (selection range of table y) as text
    on error errMsg number errNum
    set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
    return {theDoc, theSheet, theTable, theRange}
    end try
    end repeat -- y
    end if -- x>0
    end tell -- sheet
    end repeat -- i
    end tell -- document
    return {missing value, missing value, missing value, missing value}
    end getSelection
    --=====
    on decoupe(t, d)
    local l
    set AppleScript's text item delimiters to d
    set l to text items of t
    set AppleScript's text item delimiters to ""
    return l
    end decoupe
    --=====
    on parleAnglais()
    local z
    try
    tell application theApp to set z to localized string "Cancel"
    on error
    set z to "Cancel"
    end try
    return (z is not "Annuler")
    end parleAnglais
    --=====
    --[/SCRIPT]
    It's available on my idisk :
    <http://public.me.com/koenigyvan>
    Download :
    For_iWork:iWork '09:for_Numbers09:insertDateTime.zip
    Yvan KOENIG (VALLAURIS, France) dimanche 11 avril 2010 14:16:41

Maybe you are looking for