by selecting specific days of the week for the date range?

I have a table with a number of clients for about a year, but I want to only select Wednesday and Thursday of
every week, since the beginning of the dates. Table is simple and has two columns. Each line is separate from a Date
There is no duplicate of Date, it is counted for every day of the year.

column 1: number of clients, count (customer_id)
column 2: Date

Need help with the best way to achieve this.

Not sure if it is even possible to select a date in the name of the day?

Basically, I want to select every Wednesday and Thursday of each week and compare the counts during the week, the week during
week for the whole week see if charges go upwards or downwards, to get trends, thank you!

Hello

Kodiak_Seattle wrote:
I have a table with a number of clients for about a year, but I want to only select Wednesday and Thursday of
every week, since the beginning of the dates. Table is simple and has two columns. Each line is separate from a Date
There is no duplicate of Date, it is counted for every day of the year.

column 1: number of clients, count (customer_id)
column 2: Date

Need help with the best way to achieve this.

Not sure if it is even possible to select a date in the name of the day?

Sorry, we don't know what you want.

To see if a date given (dt) is a Wednesday or Thursday, you can use:

WHERE   TO_CHAR ( dt
          , 'DY'
          , 'NLS_DATE_LANGUAGE=ENGLISH'     -- If necessary
          )  IN ('WED', 'THU')

I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002}

Tags: Database

Similar Questions

  • UNPIVOT day after day in the data range


    Hi all, I am new to this forum. I have this table

    name startDT endDT value
    car1 January 14January 3, 1410
    boat2 January 145 January 1411
    plane7 January 147 January 1412

    and I want this result:

    day name value
    1 January 14

    car

    102 January 14car10January 3, 14car102 January 14boat11January 3, 14boat11January 4, 14boat115 January 14boat117 January 14plane12

    As many tanks

    I give you one example. Use the query like this

    Select t.nom,

    t.startdt + Level-1,

    t.Valeur

    of t

    connect by level<=>

    and first name = name

    and prior sys_guid() is not null

    ----

    Ramin Hashimzade

  • Disable certain days in the date picker

    Hi, I use Apex 4.2 and want to find a way to disable certain days in the date picker.

    For Ex: I want to turn off Mondays and the days of the week when the date picker popup is shown. And also I want all the previous days from today should be disabled.

    Please let me know how I can do this...

    Thank you

    Hello

    to disable different days look at this site: http://jquerybyexample.blogspot.com/2010/07/disable-specific-days-in-jquery.html

    To deactivate the days in the past, add this in: settings > Minimum Date: + 0d

    See you soon,.

    Tobias

  • get more records of 30 days from the date of the day

    I use MS SQL 2000 How can I recover the data that are older than 30 days from the date of the day? I put currendate "DateTime" field as data type and length is the '8 '.

    < cfset variables.getdate = DateAdd (would be ',-30, now()) >

    Select dataname
    of tabletest
    where currendate > = "variables.getdate."

    the sql stmt above does not work.

    Select dataname
    of tabletest
    where currendate<= #createodbcdate(dateadd("d",="" -30,="">

    You say that you want records which are more than 30 days from now, so that it must be less than or equal to the date
    But if you want the Chronogram of 30 days there are until now then it must be greater than or equal to

    Ken

  • How to write a simple select query to get the data of the table as an XML.

    How to write a simple select query to get the data of the table as an XML. In the query, I'm just adding items below which i need be there in the XML document
    select '<test_tag>'||EMP_NAME||'</test_tag>','<date>'||sysdate||'</date>' 
    from temp_table where id_num BETWEEN 1 AND 10;
    I have need to add the root tag as well in the beginning and the end of < root > < / root > this xml file. Please advice if this is possible with the select query
    without using XMLGEN, XMLQUERY or any other packages built and function?

    I need to URL escapes with the UTF-8 code points that we have already achieved using the utl_http package. Please help how to do that without using the utl_http package.

    What is wrong with him?

    At present, the only way I can think of to avoid a call to UTL_HTTP. SET_BODY_CHARSET is to write your own little wrapper.
    In this way, you can specify the Boolean parameter or omit it if you choose to use named parameters:

    SQL> create or replace function my_url_escape (url in varchar2)
      2  return varchar2
      3  deterministic
      4  is
      5  begin
      6   return utl_url.escape(url, false, 'AL32UTF8');
      7  end;
      8  /
    
    Function created
    
    SQL> select my_url_escape('http://some.uri.com/param?lang=fr&text=contrôle') from dual;
    
    MY_URL_ESCAPE('HTTP://SOME.URI
    --------------------------------------------------------------------------------
    http://some.uri.com/param?lang=fr&text=contr%C3%B4le
     
    
  • SUM (case use this structure to get average values on the date range

    I use:

    Oracle SQL Developer (3.0.04) build hand - 04.34 Oracle Database 11 g Enterprise Edition 11.2.0.1.0 - 64 bit Production

    How do we use the function sum with a structure of matter inside.

    so I gave that looks like have an ID, date and value. I'm looking to get the day 7 medium for the date range of 04/01/2013 to 20/04/2013
    with t as (
    select 1 ID_Key,to_date('4/1/2013','mm-dd-yyyy') date_val, 10 Value_num from dual union all
    select 1 ID_key,to_date('4/2/2013','mm-dd-yyyy'), 15 from dual union all
    select 1 ID_key,to_date('4/3/2013','mm-dd-yyyy'), 20 from dual union all
    select 1 ID_key,to_date('4/5/2013','mm-dd-yyyy'), 0 from dual union all
    select 1 ID_key,to_date('4/8/2013','mm-dd-yyyy'), 12 from dual union all
    select 1 ID_key,to_date('4/9/2013','mm-dd-yyyy'), 8 from dual union all
    select 1 ID_key,to_date('4/10/2013','mm-dd-yyyy'), 6 from dual union all
    select 1 ID_key,to_date('4/12/2013','mm-dd-yyyy'), 10 from dual union all
    select 1 ID_key,to_date('4/13/2013','mm-dd-yyyy'), 0 from dual union all
    select 1 ID_key,to_date('4/14/2013','mm-dd-yyyy'), 0 from dual union all
    select 1 ID_key,to_date('4/15/2013','mm-dd-yyyy'), 10 from dual union all
    select 1 ID_key,to_date('4/16/2013','mm-dd-yyyy'), 5 from dual union all
    select 1 ID_key,to_date('4/17/2013','mm-dd-yyyy'), 2 from dual union all
    select 1 ID_key,to_date('4/20/2013','mm-dd-yyyy'), 3 from dual union all
    select 2 ID_key,to_date('4/3/2013','mm-dd-yyyy'), 12 from dual union all
    select 2 ID_key,to_date('4/5/2013','mm-dd-yyyy'), 15 from dual union all
    select 2 ID_key,to_date('4/6/2013','mm-dd-yyyy'), 5 from dual union all
    select 2 ID_key,to_date('4/7/2013','mm-dd-yyyy'), 7 from dual union all
    select 2 ID_key,to_date('4/9/2013','mm-dd-yyyy'), 10 from dual union all
    select 2 ID_key,to_date('4/11/2013','mm-dd-yyyy'), 5 from dual union all
    select 2 ID_key,to_date('4/12/2013','mm-dd-yyyy'), 0 from dual union all
    select 2 ID_key,to_date('4/13/2013','mm-dd-yyyy'), 0 from dual union all
    select 2 ID_key,to_date('4/15/2013','mm-dd-yyyy'), 6 from dual union all
    select 2 ID_key,to_date('4/16/2013','mm-dd-yyyy'), 8 from dual union all
    select 2 ID_key,to_date('4/17/2013','mm-dd-yyyy'), 0 from dual union all
    select 2 ID_key,to_date('4/18/2013','mm-dd-yyyy'), 10 from dual union all
    select 2 ID_key,to_date('4/19/2013','mm-dd-yyyy'), 5 from dual
    )
    * Please let me know if the table does not load.

    I would get the average of 7 days, as long as there is date for the rank of enough previous dates, is it not, then it returns a null value.

    the results should look like this
    ID_Key      date_val     Value_num     7Day_Avg     7Day_Avg2
    1     4/1/2013     10          null          null
    1     4/2/2013     15          null          null
    1     4/3/2013     20          null          null
    1     4/5/2013     0          null          null
    1     4/8/2013     12          6.71          11.75
    1     4/9/2013     8          5.71          10.00
    1     4/10/2013     6          3.71          6.50
    1     4/12/2013     10          5.14          9.00
    1     4/13/2013     0          5.14          7.20
    1     4/14/2013     0          5.14          6.00
    1     4/15/2013     10          4.86          5.67
    1     4/16/2013     5          4.42          5.17
    1     4/17/2013     2          3.85          4.50
    1     4/20/2013     3          2.86          4.00
    2     4/3/2013     12          null          null
    2     4/5/2013     15          null          null
    2     4/6/2013     5          null          null
    2     4/7/2013     7          5.57          9.75
    2     4/9/2013     10          7.00          9.80
    2     4/11/2013     5          6.00          8.40
    2     4/12/2013     0          3.86          5.40
    2     4/13/2013     0          3.14          4.40
    2     4/15/2013     6          3.00          4.20
    2     4/16/2013     8          2.71          3.80
    2     4/17/2013     0          2.71          3.17
    2     4/18/2013     10          3.43          4.00
    2     4/19/2013     5          4.14          4.83
    As you can see, there are gaps in the dates, the value is then processed by zeros for the 7Day_Avg and then ignored for the 7Day_Avg2 (not counted in the number of days on average do to no valu_num line)
    I tried something like this at first, but becomes "missing keyword" error
    select
    t.*/,
    sum(
          case 
            when date_val between :day2 - 6 and :day2
            then value_num between date_val - 6 and date_val
            else null
            end
            )
            as 7Day_avg
    
    form t
    Should I have the structure outside the sum function?

    Any thoughts?

    Published by: 1004407 on June 7, 2013 11:06

    Hello

    If you want to calculate the average of the last 7 days, including the current day, then then RANGE should be 6 PRIOR, not 7.

    Try this:

    WITH got_min_date_val AS

    (

    SELECT id_key, date_val, value_num

    MIN (date_val) compared to (AS min_date_val)

    T

    WHERE the date_val BETWEEN TO_DATE (April 1, 2013 ', "dd-mm-yyyy")

    AND TO_DATE (April 20, 2013 ', "dd-mm-yyyy")

    )

    SELECT id_key, date_val, value_num

    CASE

    WHEN date_val > = min_date_val + 6

    THEN SUM (value_num) OVER (PARTITION BY id_key

    ORDER BY date_val

    PRIOR TO TIER 6

    )

    / 7

    END AS avg_7_day

    CASE

    WHEN date_val > = min_date_val + 6

    THEN AVG (value_num) OVER (PARTITION BY id_key

    ORDER BY date_val

    PRIOR TO TIER 6

    )

    END AS avg_7_day_2

    OF got_min_date_val

    ORDER BY id_key

    date_val

    ;

    Output:

    ID_KEY DATE_VAL VALUE_NUM AVG_7_DAY AVG_7_DAY_2

    ---------- --------- ---------- ---------- ------------

    1 1 APRIL 13 10

    1 2 APRIL 13 15

    1 APRIL 3, 13 20

    1 5 APRIL 13 0

    1 APRIL 8, 13 12 6.71 11.75

    1 APRIL 9, 13 8 5.71 10.00

    1 APRIL 10 13 6 3.71 6.50

    1 12 APRIL 13 10 5.14 9,00

    1 13 APRIL 13 0 5,14 7.20

    1 14 APRIL 13 0 5,14 6.00

    1 15 APRIL 13 10 4.86 5.67

    1 16 APRIL 13 5 4.43 5.17

    1 APRIL 17, 13 2 3.86 4.50

    1 APRIL 20, 13 3 2.86 4.00

    2 APRIL 3, 13 12

    2 5 APRIL 13 15

    2 6 APRIL 13 5

    2 7 APRIL 13 7 5.57 9.75

    2 9 APRIL 13 10 7,00 9.80

    2 11 APRIL 13 5 6.00 8.40

    2 12 APRIL 13 0 3.86 5.40

    2 13 APRIL 13 0 3.14 4.40

    2 15 APRIL 13 6 3.00 4.20

    2 16 APRIL 13 8 2.71 3.80

    2 17 APRIL 13 0 2.71 3.17

    2 18 APRIL 13 10 3.43 4.00

    2 APRIL 19, 13 5 4.14 4,83

    Post edited by: FrankKulash

    Sorry; I wanted to respond to OP, not Greg

  • Get number of records in the date range - IDE: PLSQL Developer

    I want to count the number of records of members who register within a date range specified, based on effective and expiration dates and their "elg_code". I posted the SQL code for some examples of data. What I would like to see returned is in three columns of the counties where the eff_date date_exp members fall within the date range specified by the SQL and have an Elg_code of ' ' (space).

    So what I would like is all members with elg_code ' ' where he eff_dt and exp_dt range is April 2012, 2012 MAY & JUN 2012. Thus, according to data from the sample I posted, Mark, where his elg_code record is ' ', his eff_dt is 01/01/2011 and April 2012 (30/04/2012) is his exp_dt. Range of the brand statement may 2012, but not MAY or JUNE of 2012. Marty would tally for the APR and MAY because his eff_dt is before MAY 2012 and his exp to MAY 2012. etc...

    According to the data below, the results should resemble:

    APR MAY JUN
    4-3-2

    APR should have FRANK, MARK, MARTY, MARY.
    MAY should have FRANK, MARTY, MARY
    JUN should have FRANK and MARIE

    NOAM and JOHN should not appear as his records with elg_code ' ' have no documents eff_dt and exp_dt which are April-June 2012.

    So what I tried without success as it appears that I have a kind of Cartesian question (?), is:

    Select count (m1.mbr_name) APR,
    Count (m2.mbr_name) MAY,
    Count (m3.mbr_name) JUN
    mbr2 M1,
    mbr2 m2,
    mbr2 m3
    "where m1.eff_dt < ' 01 - may - 2012"
    "and m1.exp_dt > ' 01-Apr-2012.
    and m1.elg_code = ' '
    "and m2.eff_dt < 1 June 2012"
    "and m2.exp_dt > ' 01 - may - 2012"
    and m2.elg_code = ' '
    "and m3.eff_dt < 1 July 2012"
    "and m3.exp_dt > 1 June 2012"
    and m3.elg_code = ' '


    Here's the DML

    Thanks for any help!


    create table mbr2 (mbr_name varchar (10), varchar (1) grpid eff_dt date, date of exp_dt elg_code varchar (1))
    Commit

    insert into mbr2 values ('BRAND', 'A', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (April 30, 2012 ',' DD-MM-YYYY '), ' ')
    insert into mbr2 values ('BRAND', 'A', to_date (May 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY '), 'C')

    insert into mbr2 values ('MARTY', 'A', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (May 31, 2012 ',' DD-MM-YYYY '), ' ')
    insert into mbr2 values ('MARTY', 'A', to_date (June 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY '), 'C')

    insert into mbr2 values ('FRANK', 'B', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (June 30, 2012 ',' DD-MM-YYYY '), ' ')
    insert into mbr2 values ('FRANK', 'B', to_date (July 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY ""), 'C')

    insert into mbr2 values ('MARY', 'B', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (June 30, 2012 ',' DD-MM-YYYY '), ' ')
    insert into mbr2 values ('MARY', 'B', to_date (July 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY ""), 'C')

    insert into mbr2 values ('JOHN', 'C', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (July 1, 2011 ',' DD-MM-YYYY '), ' ')
    insert into mbr2 values ('JOHN', 'C', to_date (July 1, 2011 ',' DD-MM-YYYY '), to_date (1 January 2012 ',' DD-MM-YYYY ""), 'C')

    insert into mbr2 values ("NOAM" 'd', to_date (July 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY '), ' ' ")

    Commit

    This gives you a report for the current month and the two front. Column header must be adjusted ;-)

    select
      count(
      case
      when
        eff_dt < add_months(trunc(sysdate,'MM'), -1)
        and
        exp_dt >= add_months(trunc(sysdate,'MM'), -2)
      then 1
      end) April
    , count(
      case
      when
        eff_dt < add_months(trunc(sysdate,'MM'), 0)
        and
        exp_dt >= add_months(trunc(sysdate,'MM'), -1)
      then 1
      end) May
    , count(
      case
      when
        eff_dt < add_months(trunc(sysdate,'MM'), 1)
        and
        exp_dt >= add_months(trunc(sysdate,'MM'), 0)
      then 1
      end) June
    from mbr2
    where
    elg_code = ' '
    and
    eff_dt < add_months(trunc(sysdate,'MM'), 1)
    and
    exp_dt >= add_months(trunc(sysdate,'MM'), -2)
    
    APRIL     MAY     JUNE
    4     3     2
    
  • On the date ranges in search of oracle forms

    I use service number, name, type person and date as search criteria in the custom form ranges.
    When I enter the employee number, press the search button, I get the exact info in the block of result.
    Result block contains
    name of the employee, personid, emp numbed, org, start_date.
    Similarly when I enter the employee number, dept, I get the correct values.
    My question is, when I enter the date range. IAM unable to filter the data.
    When I enter START_DATE between nvl(:BLOCKNAME.) Start_date, 1 January 1901 ') and nvl(:BLOCKNAME.) End_date, 31-DEC-4712') where block clause in the result. I had data for the range of dates also.

    If I give condition in where clause results take so long when I search with the name of the employee, number, dept, person type.

    If I have a query with the date, the persormance is good.

    Think you know everything, how it prevents START_DATE between nvl(:BLOCKNAME.) Start_date, 1 January 1901 ') and nvl(:BLOCKNAME.) End_date, 31-DEC-4712') when look us with the employee's name, number, dept, person type.

    So leave the WHERE clause of your empty block and put something like the following in your search button:

    IF    :BLOCK.START_DATE IS NOT NULL
       OR :BLOCK.END_DATE IS NOT NULL THEN
      SET_BLOCK_PROPERTY('YOURBLOCK', ONETIME_WHERE, 'START_DATE between nvl(:BLOCKNAME.START_DATE,TO_DATE(''01-JAN-1901'', ''DD-MON-YYYY'')) and nvl(:BLOCKNAME.END_DATE,TO_DATE(''31-DEC-4712'', ''DD-MON-YYYY''))');
    END IF;
    
  • Formula to determine if a specific day of the week between two dates?

    I am creating a spreadsheet to track my time PD & holiday. I usually work weekends, and my vacation allowance includes a specific maximum number of Sundays a year. Is there a way to calculate how much Sunday fall between a date range (or any day of the week, by the way)?

    (i.e. If my vacation starts February 1, 2016 and ends March 2, 2016, Sunday how are included?)

    I know that I can calculate how many weeks have passed, using = Quotient (DateDiff (Start_Date, End_Date), 7), but it is possible to include two Sundays in a period of 7 days.

    Hi Eric,.

    Here is one approach.

    C2 = A2 + (7−WEEKDAY(A2,2))

    This concludes the first Sunday following the start date.

    D2 = STRIPDURATION ((B2−C2) ÷7)

    I formatted this column without decimal places to see full weeks of the first numbers Sunday.

    Quinn

  • Mail for specific days of the user and specific and time

    Hello Experts,

    I use the program below to email each daily hour. This was intended for one person.

    Now I have to change my program to accommodate more than one person, and also, I should be able to send emails to people on time and different days. What is the best approach to
    declare
    x_val               long;
    x_cumm_val          long;
    x_title             long;
    x_cumm_title        long;
    x_footer            long;
    x_column_header     long;
    x_column_line       long;
    x_row_header        long;
    x_row_line          long;
    x_cumm_row_line     long;
    x_total_header      long;
    x_total_line        long;
    x_row               long;
    x_cumm_row          long;
    l_rec_time          varchar2(25);
    l_order_id          number;
    l_amt               number;
    l_cumm_amt          number;
    l_instant_cumm_amt  number;
    l_instant_game_id   number :=-1;
    l_instant_col_val   number :=2;
    l_instant_cumm_val  number :=0;--keep cummalative amt for instant
    l_product           varchar2(25);
    no_chance           exception;
    x_cnt               number :=0;
    l_date              date := trunc(sysdate);
    x_to                long ;
    c_cc                 long := '[email protected]';
    x_recipient          long := '[email protected]';
    x_exec_recipien      long := '[email protected]';
    x_gamma_recipient long := '[email protected]';
                                
                                
    
    CURSOR c_get_values IS
    select nvl(sum(act_amt),0)
    from hourly_sales
    where  trunc(sys_date) =l_date
    and nvl(confirmed,'!') = 'Y' 
    and to_char(to_date(rec_time,'HH24:MI'),'HH24:MI') = to_char(to_date(l_rec_time,'HH24:MI'),'HH24:MI')
    and order_id =l_order_id;
    
    CURSOR c_get_Instant_val IS
    select nvl(sum(act_amt),0)
    from hourly_sales
    where  trunc(sys_date) =l_date
    and nvl(confirmed,'!') = 'Y' 
    and to_char(to_date(rec_time,'HH24:MI'),'HH24:MI') = to_char(to_date(l_rec_time,'HH24:MI'),'HH24:MI')
    and product='INSTANT';
    
    CURSOR c_get_user IS
    select email_address
    from apex_user
    where user_name =p_person
    and default_schema ='LOTTO_BI';
    begin
    
         x_title := '<html><head> '
                    ||'<body>'
                    ||'<h3 align="left"><u><font color="#000080"> Hourly Sales for '||to_char(l_date,'FMMonth DD, YYYY')
                    ||'</font></u></h3></body></html>';
                
      x_cumm_title := '<html><head> '
                    ||'<body>'
                    ||'<h3 align="left"><u><font color="#000080"> Cumulative Hourly Sales for '||to_char(l_date,'FMMonth DD, YYYY')
                    ||'</font></u></h3></body></html>';
              
      x_column_header :=  '<table border="1" bordercolor="#000000" style="background-color:#ffffd2" width="400" cellpadding="3" cellspacing="3"> '
                           ||'<TR>  <TD>    </TD> ';
                                       
       x_footer := '<p>This Email is autogenerated. For any inquiry please '||
                        ' Email on <a '||
                        'href="mailto:[email protected]">[email protected]</a>.</p>'||
                        '<p> </p>'||
                        '<p> </p></body></html>';
                                   
        if p_person is not null then
            
            OPEN C_GET_USER;
            FETCH C_GET_USER INTO x_to;
            IF C_GET_USER%NOTFOUND THEN 
              x_val := 'No email address defined for '||p_person;
              raise no_chance;
            END IF;
            CLOSE C_GET_USER;
            x_cc := null;--do n0t copy operations when testing mail  
        else
        
          if ltrim(rtrim(to_char(SYSDATE,'DAY'))) in('FRIDAY','SATURDAY') then     
           x_to := x_recipient||' , '||x_exec_recipient;
           
            if ltrim(rtrim(to_char(SYSDATE,'DAY'))) = 'SATURDAY' then
                x_to := x_to||' , '||x_gamma_recipient;
            end if;     
           
          else
           x_to := x_recipient;
          end if;      
           
        end if;                 
                                                                       
                                
       for c1 in( select game_id,product product_id,b.display_name product,b.ordering
                  from hourly_sales a,
                       games b
                  where a.game_id =b.id
                  and b.active = 'Y'                  --<< Addition of condtion for active games only
                  and trunc(a.sys_date) =l_date
                  and nvl(a.confirmed,'!') = 'Y' 
                  group by a.game_id,a.product,b.display_name,b.ordering
                  UNION 
                  select -1,'INSTANT','Instant',l_instant_col_val
                  from dual
                  order by 4
                  )
    
                    loop--c1
                           
                        if c1.product is null then
                           x_val := 'Invalid or Unrecognized Product retrieved from database';
                           raise no_chance;                       
                        end if;
    
                        x_column_line := x_column_line|| '<TH> ' ||c1.product||' </TH>';
                        x_cnt := x_cnt +1;
                        
                        update hourly_sales
                        set order_id  = x_cnt
                        where  trunc(sys_date) =l_date
                        and nvl(confirmed,'!') = 'Y'
                        and game_id =c1.game_id
                        and product =c1.product_id;
                        
                    end loop;--c1
    
                    
                    x_column_line := x_column_line||' </TR>';
                    
                    if x_cnt =0 then
                        x_val := 'No Hourly sales data to send for '||to_char(l_date,'FMMonth DD, YYYY');
                        raise no_chance;
                   end if;
                     
                   
                    
                    for c2 in(select rec_time
                                 from rec_time
                                 group by rec_time
                                 order by 1
                                 ) 
                                 
                                 loop--c2
                                 
                                    l_rec_time := c2.rec_time;
                                    
                                    x_row_header := ' <TR> <TH>'||c2.rec_time||'</TH> ';
                                    
                                            for i in 1..x_cnt
                                           loop
                                            
                                                l_order_id := i;
                                                l_cumm_amt := null;--reset of cummulatice amt for each game
                                                
                                               if l_order_id = l_instant_col_val then --INSTANT Total Sales
                                                    
                                                  OPEN c_get_Instant_val;
                                                  FETCH c_get_Instant_val INTO l_amt;
                                                  l_instant_cumm_val := l_instant_cumm_val + l_amt;
                                                  IF c_get_Instant_val%NOTFOUND THEN
                                                    x_row_line := x_row_line||' <TD><p align="center"> - </p></TD> ';
                                                    l_cumm_amt := 0;
                                                  ELSE
                                                    x_row_line := x_row_line||' <TD><p align="center">'||to_char(l_amt,'999,999,999,999,999,999,999,999,999')||'</p></TD> ';
                                                   /* Assume @ this stage that if previous record <>0 for instant sales column
                                                      next record should have value else no hourly sales yet input.
                                                   */
                                                    if l_amt = 0 then
                                                     l_cumm_amt := 0 ;
                                                    else
                                                     l_cumm_amt := l_instant_cumm_val;
                                                    end if;
                                                     
                                                  END IF;
                                                  
                                                  CLOSE c_get_Instant_val;
                                                  
                                               ELSE
                                           
                                                OPEN c_get_values;
                                                FETCH c_get_values INTO l_amt;
                                                IF c_get_values%NOTFOUND THEN
                                                   x_row_line := x_row_line||' <TD><p align="center"> - </p></TD> ';
                                                   l_cumm_amt := 0;
                                                ELSE
                                                  x_row_line := x_row_line||' <TD><p align="center">'||to_char(l_amt,'999,999,999,999,999,999,999,999,999')||'</p></TD> ';
                                                 
                                                 if l_amt <> 0 then  
                                                   --save values into temp table for cummulative
                                                  insert into cumm_hourly_sales
                                                  (game_id,
                                                   amt)
                                                   values
                                                  (l_order_id,
                                                   l_amt);   
                 
                                                   select (sum(amt))
                                                   into l_cumm_amt
                                                   from cumm_hourly_sales
                                                   where game_id = l_order_id;
                                                 
                                                 else
    
                                                    l_cumm_amt := 0;
                                                 
                                                 end if;
                                                  
                                                END IF;
                                               
                                                CLOSE c_get_values;
                                               
                                                end if;
                                                
                                                   x_cumm_row_line := x_cumm_row_line||' <TD><p align="center">'||to_char(l_cumm_amt,'999,999,999,999,999,999,999,999,999')||'</p></TD> ';
    
                                            end loop;
                                            
                                       x_row := x_row||x_row_header||x_row_line;    
                                       x_cumm_row := x_cumm_row||x_row_header||x_cumm_row_line;    
                                       
                                       --reinitialise variables
                                       x_row_header := null;
                                       x_row_line := null;
                                       x_cumm_row_line := null;
                                       
                                 
     
                                 end loop;--c2
                                    
                                  x_total_header := ' <TR> <TH> Total </TH> ';
                                 --Total count
                                 for c3 in( select order_id,sum(act_amt)amt
                                            from hourly_sales
                                            where  trunc(sys_date) =l_date
                                            and nvl(confirmed,'!') = 'Y' 
                                            group by order_id
                                            union all
                                            select 2,sum(act_amt)amt--Total for Instant Sales (value 2 should be ok since order 2 do not exist on table) 
                                            from hourly_sales
                                            where  trunc(sys_date) =l_date
                                            and nvl(confirmed,'!') = 'Y'
                                            and product ='INSTANT' 
                                            group by 2
                                            order by order_id)
                                            
                                            loop                                                       
                                             x_total_line := x_total_line||' <TD><p align="center"><strong><em>'||to_char(c3.amt,'999,999,999,999,999,999,999,999,999.99')
                                                                   ||'</em></strong></p></TD> ';
                                            end loop;
                                                
                                                 x_row := x_row||x_total_header||x_total_line;                
                                                 x_val  :=  x_title||x_column_header||x_column_line||x_row||' </TABLE> '||x_footer;
                                                 x_cumm_val :=x_cumm_title||x_column_header||x_column_line||x_cumm_row||' </TABLE> '||x_footer;
                    
           
        apex_send_mail(  l_from => '[email protected]',
                                    l_to => x_to,
                                    l_body => x_val ,
                                    l_subject => 'Hourly Sales for '||to_char(l_date,'FMMonth DD, YYYY'),
                                    l_cc => x_cc
                                );
                                
        apex_send_mail(  l_from => '[email protected]',
                                    l_to =>  x_to,
                                    l_body => x_cumm_val ,
                                    l_subject => 'Cumulative Hourly Sales for '||to_char(l_date,'FMMonth DD, YYYY'),
                                    l_cc => x_cc
                                );
                                
                                
    exception
    when no_chance then 
    --send mail
    IF c_get_values%ISOPEN THEN CLOSE c_get_values;END IF;
    IF c_get_user%ISOPEN THEN CLOSE c_get_user;END IF;
    apex_send_mail(  l_from => '[email protected]',
                               l_to =>'[email protected]',
                               l_body => x_val ,
                               l_subject => 'Hourly Sales for '||to_char(l_date,'FMMonth DD, YYYY'),
                               l_cc => '[email protected]'
                            );
    when others then
     --send mail
     IF c_get_values%ISOPEN THEN CLOSE c_get_values;END IF;
     IF c_get_user%ISOPEN THEN CLOSE c_get_user;END IF;
     x_val :='Unexpected Error '||sqlerrm;
    apex_send_mail(  l_from => '[email protected]',
                               l_to =>'[email protected]',
                               l_body => x_val ,
                               l_subject => 'Hourly Sales for '||sysdate,
                               l_cc => '[email protected]'
                           );
    end;
    /

    Hey Kevin,

    If I understand your condition, you could do this with two tables:
    something like this:

    Table 1: Recipients_lookup
    
    DAY          RECIPIENTS
    MONDAY          [email protected],[email protected],[email protected]
    TUESDAY          [email protected],[email protected],[email protected]
    WEDNESDAY     [email protected],[email protected],[email protected]
    THURSDAY     [email protected],[email protected],[email protected]
    FRIDAY          [email protected],[email protected],[email protected]
    SATURDAY     [email protected],[email protected],[email protected]
    SUNDAY          [email protected],[email protected],[email protected]
    

    First, you must select the recipients in table 1 to help 'day' of sysdate. store in a global variable for that particular day.

    Insert date time records in table 2, something like this:

    Table 2: date_time_lookup
    
    DATE          TIME          SENT_FLAG
    30-Apr-10     10:00 AM     Y
    30-Apr-10     11:00 AM     Y
    30-Apr-10     12:00 PM     Y
    30-Apr-10     1:00 PM
    30-Apr-10     2:00 PM
    30-Apr-10     3:00 PM
    30-Apr-10     4:00 PM
    ...
    

    Once done, make your program (to generate/send by email) to run for the first hour of the day.
    Use dbms_lock.sleep (3600) to sleep for 1 hour then call your procedure again
    to do this, until you reach some "end time" (7 PM or so consider you want it to be sent only during working hours...) for the day, after which, your code still needs to wait until the next day.

    Tip: just go through this link on dbms_lock.sleep and use accordingly:
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:6019886867656

    * This is based on my initial understanding of your condition. Could be too long :)

    Concerning
    Imran

  • find the days from the date of...

    Hi all

    I have a date saying (06-mar-2009), then how do you know what day is the same day as today (Friday)... and I need to create a table based on another table and must include all dates it's Saturday...

    If someone can help me...

    Thank you
    Pankaj

    If you are looking for the week then->

    CREATE TABLE test
    AS
      SELECT *
      FROM emp
      where to_char(hiredate,'DY') NOT IN ('SAT','SUN');
    

    Another thing,

    CREATE TABLE test
    AS
      SELECT *
      FROM emp
      where to_char(hiredate,'DY') IN ('SAT','SUN');
    

    Alternatively,.

    Please post your desired output of your sample data.

    Kind regards.

    LOULOU.

  • Get the date range min/max for consecutive events.

    Hi all...

    I am fairly new to the programming of the DB and is working on some examples I picked up a few places. The database version is 10g R2.

    I would like to configure the data here and I can explain my requirement.

    create table table_1
    (product_id varchar2(25),
    region_id  number,
    event_id number
    event_date date,
    event_status number(1))
    /
    
    
    

    Now the data because it is->

    insert into table_1 values ('Prod-1',10, null, to_date('01-feb-2014','dd-mon-yyyy'),null)
    /
    insert into table_1 values('Prod-1',10, 1001, to_date('10-mar-2014','dd-mon-yyyy'), 1)
    /
    insert into table_1 values('Prod-1',10, 1001, to_date('20-mar-2014','dd-mon-yyyy'), 3)
    /
    insert into table_1 values('Prod-1',10,1002, to_date('01-apr-2014','dd-mon-yyyy'), 1)
    /
    insert into table_1 values('Prod-1',10, 1002, to_date('10-apr-2014','dd-mon-yyyy'), 3)
    /
    commit
    /
    
    
    
    

    If the table now contains the following data

    select * from table_1; 
    
    
    

    PRODUCT_ID REGION_ID EVENT ID EVENT_DAT EVENT_STATUS

    ------------------------- ---------- -------- --------- ------------

    Prod-1 10 1 February 14

    Prod-1 10 1001 10 March 14 1

    Prod-1 10 1001 20 March 14 3

    Prod-1 10 1002 1 April 14 1

    Prod-1 10 1002 April 10, 14 3

    Now, the condition is as follows:

    Above is the dates start and end for the tests on a product in a given region. The event_status column indicates the dates of beginning and end. Event_status = 1, for the date of beginning and the event_status = 3 of the end date.

    A new event is now coming from March 21 and ending on March 31.

    The power required is a product identifier / region; If there are events that are ending and then count the days, for example, 1001 to end on March 20, but now the new event begins on 21 March... and the new event ends on 31 March and event 1002 begins 01 - Apr... and so on.

    The output required for this is as follows:

    PRODUCT_ID REGION_ID EVENT_MIN_DATE EVENT_MAX_DATE

    ------------------------- ---------- -------------- --------------

    Prod-1 10 10 14 March 10 April 14

    The output should give a product identifier / region, when events are immediately after the other, out the min date of beginning and end of max for all these manifestations of "back to back".

    Now I wrote the code for this, but it goes into a purely 'loop' for application in PLSQL... But my head tells me that if the results are correct. the PLSQL implementation is not the most efficient and effective way.

    Can someone help me to form the query? I tried to use functions analytical min/max but it gives me the start and end dates back even if my events are not "back to back" or previous/succeed each other... so my query result is not quite correct.

    Am reading on the TYPE clause but would be grateful if someone could help me with this query... or any other form better to implement this event so PLSQL can be used. The database version is 10g R2.

    Thank you

    K

    PS - The number of such events back to back is limited to 4 and the events could be created in any order. But if someone could help me with the scenario above; am sure I could make a request addressed to any change in the order. :-)

    No this isn't a recursive with clause, perhaps the UNION ALL you got confused. She will work with 10g.

    Since there are 2 tables that you said, the block all_data brings together only the lines of the two tables. table_1 start_date and end_date are built from the event_status (where the max in group by).

  • Validate the difference in days between the dates in a table

    Greetings,

    I have a tabular form and date on each line. When the user saves the form, I want to sort the rows by chronological order of these dates, then go get the first and last date, calculate the difference between them and validate it.

    Does anyone know how to do?

    From now on, I came up with this:

    1. a PL/SQL Page process "before the calculations and Validations' which creates a collection and inserts lines in my tabular form (p_c004 being the date field):
    begin   
      if apex_collection.collection_exists('UPDATE_DATES') then
        apex_collection.delete_collection('UPDATE_DATES');
      end if;
    
      apex_collection.create_or_truncate_collection('UPDATE_DATES');
    
      for i in 1..apex_application.g_f04.count
      loop
          apex_collection.add_member(
              p_collection_name => 'UPDATE_DATES',
              p_c002            => htmldb_application.g_f02(i),
              p_c003            => htmldb_application.g_f03(i),
              p_c004            => htmldb_application.g_f04(i),
              p_c005            => htmldb_application.g_f05(i),
              p_c006            => htmldb_application.g_f06(i),
              p_c007            => htmldb_application.g_f07(i));
      end loop;
    end;
    and

    2. a "PL/SQL Error: Validation
    DECLARE
      l_count NUMBER;
    BEGIN
      apex_collection.sort_members('UPDATE_DATES', 4);
      l_count := apex_collection.collection_member_count('UPDATE_DATES');
    
      SELECT
      to_date(c004(l_count),'DD/MM/YYYY') - to_date(c004(1),'DD/MM/YYYY') Difference 
    
      FROM 
      apex_collections 
    
      WHERE 
      collection_name = 'UPDATE_DATES'
      and to_date(c004(l_count),'DD/MM/YYYY') - to_date(c004(1),'DD/MM/YYYY') < 30;
    
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        raise_application_error(-20101, 'Error');
    END;
    In my understanding, the validation must sort the collection in chronological order of the dates entered, calculate the difference in days between the nearest and farthest date and return it if it's less than 30 years (the difference in days allowed). If it's more than 30 years, the SELECT statement does not return anything and my block of exceptions raises a custom error that will trigger the validation "process of refusal."

    But when I try this, it tells me c004 does not exist and if I drop the parentheses, it works, but of course, it does not give the desired result.

    Any ideas?

    Best regards
    Mathieu

    Assuming that your domain is c004 then I don't see the need for the sorting of the collection.

    You can write a simple SQL select that sent you the desired result.

    Maybe something like this not tested

    SELECT
      max(to_date(c004,'DD/MM/YYYY')) - min(to_date(c004,'DD/MM/YYYY') ) Difference
      FROM apex_collections
      WHERE collection_name = 'UPDATE_DATES';
    

    The test if the result is > 30 days. If that's what you want to know.

  • Clone a model in a specific folder on the data, with powercli store?

    I'm deploying approximately 135 VM from an unique model using powercli from a CSV file.

    Each line in the CSV file has a connection, course section instructor

    For example...

    Login Section instructor

    123456 5555 Foo EE123

    Here is the script

    SE connect-VIServer-Server 10.0.0.60 - Credential (Get-Credential)
    $Users = import-Csv c:\CSV\Data.csv
    {foreach ($User in $Users)
    $Login = $User.Login
    $Course = $User.Course
    $Section = $User.Section
    $Instructor = $User.Instructor
    $ResPool = $User.Section + "" + $User.Instructor
    New-VM - VMHost 10.0.0.10 - name $Login - ResourcePool "$ResPool" - model 'VM-model' - data store "datastore1".
    write "$Login Created" | Out-file "log.txt" - append
    }
    Disconnect-VIServer-Server 10.0.0.60 - confirm: $false

    I'm doing the data store a little cleaner when I deploy these machines and put all the machines in a folder located in the data store, for example. datastore1\spring2013\EE123\ (in reality would have $Course instead of EE123)

    Can someone help me with this.


    Thanks in advance

    Yes, you can use the ResourcePool parameter on the New - VM cmdlet to do this.

    But since you have resourcepools with the same name in the tree, you must be sure to only select the right pair.

    You use the location setting to indicate which branch of the tree you want.

    For example:

    $rpRoot = get-ResourcePoo-name 'Sprint 2013"

    $rpCourse = get-ResourcePoo-name 'Foo 5555"- location $rpRoot

    $rpServers = get-ResourcePoo-name "servers" - location $rpCourse

    $rpStudents = get-ResourcePoo-name 'students' - location $rpCourse

    New-VM-name--ResourcePool $rpStudents

    You can create this logic in a loop and use the name of a CSV file example

  • You press on delete all selected items by browsing the data store and accidentally deleted a vmdk file which has the OS on it

    I accidentally deleted the vmdk file that has my OS on it by pressing the "Delete selected items" button in the window of browser data store. Is there anyway to recover? I have a snapshot that doesn't seem to work. There is still the VMDK file in there, but it has now 'delta' be added at the end. Now I get an error message when I try to turn on my VM saying that he doesn't get the vmdk file, of course.

    delta.PNG

    errorVMDK.PNG

    From the screen shots looks you have deleted only the descriptor hard files that can be recreated. To ensure this is the case, please provide a complete list of the files in the folder of the virtual machine and attach the last file.log of vmware(from the virtual work computer) to a post response to view required details.

    André

Maybe you are looking for