Query to group dates based on days of week

Hi,
I have a table containing the following format:
Create table testtable(dates date, day_identifier number);
The day_identifier column data contains the corresponding dates columns' day of week equivalent i.e.
to_char(dates, 'd')
The table contains following sample data:
Dates
Day_identifier
01-Oct-2013
3
02-Oct-2013
4
04-Oct-2013
6
06-Oct-2013
1
08-Oct-2013
3
09-Oct-2013
4
11-Oct-2013
6
18-Oct-2013
6
21-Oct-2013
2
23-Oct-2013
4
I am looking for a query that will group the above data based on the day_identifier column data into the following format:
01-Oct-2013 11-Oct-2013 1346
18-Oct-2013 23-Oct-2013 246
The above data if expanded i.e.
all dates between 01-Oct-2013 and 11-Oct-2013 and having day of week value in 1,3,4,6
and
all dates between 18-Oct-2013 and 23-Oct-2013 and having day of week value in 2,4,6
will give me the above table's resultset.
Please help me in resolving the issue.
Thanks.

with
groups as
(select 'one' grp,
        to_date('01-Oct-2013','dd-Mon-yyyy') low_date,
        to_date('06-Oct-2013','dd-Mon-yyyy') high_date,
        '3,5,7' day_identifiers from dual union all
select 'two',to_date('10-Oct-2013','dd-Mon-yyyy'),to_date('16-Oct-2013','dd-Mon-yyyy'),'1,2' from dual union all
select 'six',to_date('20-Oct-2013','dd-Mon-yyyy'),to_date('26-Oct-2013','dd-Mon-yyyy'),'4,5,6' from dual
dates as
(select trunc(sysdate,'mm') + level - 1 the_date,to_char(trunc(sysdate,'mm') - level - 1,'d') day_identifier
   from dual
connect by level <= to_number(to_char(last_day(sysdate),'dd'))
select d.the_date,d.day_identifier,g.grp,g.low_date,g.high_date,g.day_identifiers
  from dates d,
       groups g
where d.the_date between g.low_date(+) and g.high_date(+)
   and instr(','||g.day_identifiers(+)||',',','||d.day_identifier||',') > 0
THE_DATE
DAY_IDENTIFIER
GRP
LOW_DATE
HIGH_DATE
DAY_IDENTIFIERS
10/01/2013
1
10/02/2013
7
one
10/01/2013
10/06/2013
3,5,7
10/03/2013
6
10/04/2013
5
one
10/01/2013
10/06/2013
3,5,7
10/05/2013
4
10/06/2013
3
one
10/01/2013
10/06/2013
3,5,7
10/07/2013
2
10/08/2013
1
10/09/2013
7
10/10/2013
6
10/11/2013
5
10/12/2013
4
10/13/2013
3
10/14/2013
2
two
10/10/2013
10/16/2013
1,2
10/15/2013
1
two
10/10/2013
10/16/2013
1,2
10/16/2013
7
10/17/2013
6
10/18/2013
5
10/19/2013
4
10/20/2013
3
10/21/2013
2
10/22/2013
1
10/23/2013
7
10/24/2013
6
six
10/20/2013
10/26/2013
4,5,6
10/25/2013
5
six
10/20/2013
10/26/2013
4,5,6
10/26/2013
4
six
10/20/2013
10/26/2013
4,5,6
10/27/2013
3
10/28/2013
2
10/29/2013
1
10/30/2013
7
10/31/2013
6
Regards
Etbin

Similar Messages

  • Crosstab Query re Grouping Data into Value Ranges

    Hi
    I am trying to analyse some data in a Crosstab & have a query re grouping.
    The data contains sales transaction info such as selling price, quantity etc. I would like to create a grouping in the Crosstab based on a sale price range (eg £0 - £10, £10 - £20 etc) so that I can show the total quantity sold in each price range.
    To date my method has been to create a formula with Select Case which identifies each transaction into a price range. I would then use this formula in my Crosstab. The main issue with this method is that there will be a large number of Cases & the possibility this will need to be added to / modified going forward.
    Whilst I think this will work I am hoping there is better method to follow?
    Thanks
    Jon

    Hi Jamie,
    Thank you for your help.
    I'm looking to group in increments of 10 so it looks like the Floor function will do the trick, thank you.
    I'll probably use an If statement to do a "block" of prices at either end of the scale (ie < 100 then 100, > 1000 then 1000+ else Floor ({Sales Field},10). Hopefully this way I'll reduce the overall no of rows.
    Thanks again for your help.
    Jon

  • How to control outer group data based on inner group data

    Hi ,
    Please can anyyone help me on this issue.
    I have one invoice header record and for that invoice there are 15invoice lines record.
    1)my requirement is i want to print the 10 invoice records in first page and remaining records,in next page.--this i had achieved*(byusing solution posted inthe forum)*
    i have the layout like this
    image:!C:\Documents and Settings\madhu.rn\Desktop\layout.jpg!
    main group data table
    i had inserted another table for inner group data.
    again main group data in main table.
    2)But here i don't want print header info again in second page.
    3)i am not getting the line numbers in inner group in ascending order ,i am getting in descending order. how to get them in decending order
    4) if lines record are going to second page i don't want to print subtotal,tax,total (these are main group data)in first page, instead of this
    in place of
    subtotal-- want to print Continued......
    Tax- null
    Total:page 1 of 2. like that i want to print in first page.
    i want them to print in second page.
    5)the bottom portion also not to print on second page.(after innergroup data,there is some main group data)
    i have one doubt by using inner group data whether we can control outer group data.
    if any of my requirement's are not possible to meet ,please provide me the information.
    This urgent for me,have to submit it.
    Edited by: user644268 on Feb 8, 2010 11:10 AM

    Hi,
    Please help me in this issue. Its an urgent requirement.
    Thanks in Advance..

  • Query Problem - Group data by time

    I have statistic data that record by time such as
    Time Data
    19-MAR-06 10:01 100
    19-MAR-06 10:02 100
    19-MAR-06 10:03 100
    19-MAR-06 10:04 100
    19-MAR-06 10:05 100
    19-MAR-06 10:06 100
    I would like to group data every five minute start from 00:00 to 23:59 for example the result should be
    Time Sum(Data)
    19-MAR-06 00:00 0
    19-MAR-06 00:05 0
    19-MAR-06 10:00 400
    19-MAR-06 10:05 200
    Any suggest?

    SELECT times.all_time, NVL(real.sum,0)
    FROM
       (SELECT  mintim + (level * (1/12/24)) - 1/12/24 AS all_time
        FROM    ( SELECT trunc(MIN(time),'DD') mintim
                       , trunc(MAX(time),'DD') + 1 maxtim
                  FROM   testtab
        CONNECT BY mintim + (level * (1/12/24)) - 1/12/24 <= maxtim
        ) times,
       (SELECT TRUNC(time,'HH24') +
              (TRUNC(TO_CHAR(time,'MI')/5)*5)/24/60 real_time, sum(data) sum 
        FROM testtab                      
        GROUP BY  TRUNC(time,'HH24') + (TRUNC(TO_CHAR(time,'MI')/5)*5)/24/60) real
    WHERE times.all_time = real.real_time(+)  
    ORDER BY times.all_time
    19-Mrz-2006     0
    19-Mrz-2006 0:05:00     0
    19-Mrz-2006 0:10:00     0
    19-Mrz-2006 0:15:00     0
    19-Mrz-2006 9:45:00     0
    19-Mrz-2006 9:50:00     0
    19-Mrz-2006 9:55:00     0
    19-Mrz-2006 10:00:00     400
    19-Mrz-2006 10:05:00     200
    19-Mrz-2006 10:10:00     0
    19-Mrz-2006 23:45:00     0
    19-Mrz-2006 23:50:00     0
    19-Mrz-2006 23:55:00     0
    20-Mrz-2006     0

  • Sql query to fetch data based on date conditons

    Hi All,
    We have to schedule a script that runs at 1:00 AM from Monday to Friday.
    The script will run a  sql query  ,that will fetch the data from sql database 2008 based on the below conditions.
    Case 1: If date = current Date then retrieve the data of the previous Date.
    Case 2: If date = Monday then retrieve the entries of Friday ,Saturday and Sunday.
    Please help us on how we can achieve this.
    Thanks

    Hi,
    Are you asking about Patrick's
    solution?
    If so I highly recommend NOT to use this solution. PLease read LMU92's
    and
    Visakh16's responses.
    Why not to use it?
    1. This solution is not deterministic!
    A deterministic algorithm is an algorithm which, given a particular input, will always produce the same output. This solution give different values for different setting! It is depending for example on "SET LANGUAGE" value
    As mentioned above if you try to use any other languge then English then this query will not work since you will never get the value "Sunday"
    2. Moreover! Even if you are using "SET LANGUAGE 'English'" then this
    solution depend on "SET DATEFIRST" and only take into consideration that the value can be 1 or 7, using any other value you will get that @weekendDateMod is null!
    What can you use?
    let's test some value first to get the solution yourself. We know that we don't care about "SET LANGUAGE" since I will not use any language dependency but we need to examine "SET DATEFIRST". Try to change the value from 1 to 7 and check
    the value of this query
    SET DATEFIRST 1 -- Change this value from 1 to 7!
    DECLARE @Sunday DATE = '2014-08-03' -- This is Sunday
    DECLARE @Munday DATE = '2014-08-04' -- This is Munday
    SELECT DATEPART(DW,@Sunday),DATEPART(DW,@Munday), @@DATEFIRST
    Can you see the behavior ?
    The results are hidden here (select the text and you will see them)
    DATEFIRST___Sunday_______Monday
    1___________7___________1
    2___________6___________7
    3___________5___________6
    4___________4___________5
    5___________3___________4
    6___________2___________3
    7___________1___________2
    assuming you did the exercise above yourself, then  you can now think now what is the filter that you need...
    You can use a filter on those two parameters together using "where DATEPART... and @@DATEFIRST...) or using one combine check. Can you think how?
    Notice that this value is always 2 on Monday! Regarding our setting
    (DATEPART(DW,@CurrentDate) + @@DATEFIRST) % 7
    Please Don't Go Down Before YOu Understand!
    Now we can go to the solution
    * I really hope that you read all and did the small exercise yourself! You can not become a developer by copy answers, and this is the reason that from the start I only gave you tha way and not the final query!
    DECLARE @CurrentDate DATE = '2007-08-20' -- This is only for testing since you should use the function GETDATE() instead
    DECLARE @MinDateToFilter DATE
    SET @MinDateToFilter = CASE
    WHEN ((DATEPART(DW,@CurrentDate) + @@DATEFIRST) % 7) = 2 THEN DATEADD(DAY,-4,@CurrentDate)
    ELSE DATEADD(DAY,-1,@CurrentDate)
    END
    SELECT *
    FROM sales.salesOrderHeader
    WHERE orderDate > @MinDateToFilter
    I hope this was useful :-)
    [Personal Site] [Blog] [Facebook]

  • SQL query to group data by Code and dates

    Hi There,
    I have the following table structure
    col1 col2 col3
    code1 21-jan-2012 tested
    code1 20-jan-2012 tested
    code1 01-jun-2012 tested
    code2 01-jun-2012 tested
    code3 04-jun-2012 tested
    so on
    The output should be some thing like
    code Week1 week2 week 3 week4 week5 till about last 14 weeks from the date we are running
    code1 1 0 0 0 0
    code2 1 0 0 0 0
    code 3 0 1 0 0 0
    where 1, 0 is actually the counts and not sum and the week in this case, should have maybe been since we are in the second week it should have been
    code .....................week3 may week4 may week1 jun week2june
    Was looking for suggestions on how to get this done.
    I am assuming this would require some sort of a pivot query?
    Thanks,
    Sun

    Hi, Sun,
    sun1977 wrote:
    Thanks EKH,
    Yes, in lines of the output of this query. Is it possible to,
    1. In the query, if condition is met, the it simply displays 1 else 0. Basically, we need to get the count of the number of the codes in that week. So if code 1 happened 5 times, it should show 5.Sure; use COUNT instead of MAX.
    2. Provide the output between two dates. Lets say, I have to do it for the last 14 weeks from sysdate. Then will the logic of week1 = 1 work?Use date arithmetic to get the number of days between the starting date and col2, then divide by 7 to get the number of weeks. Use that number instead of the value returned by TO_CHAR.
    3. any suggestions if the counts have to be changed to percentages. How can we have the percentage value showingYou can do that. Exactly how depends on exactly what you want. It may involve using the analytic RATIO_TO_REPORT function in a sub-query. Post the exact results you want from the sample data that Ekh posted (or new sample data that you post), and explain how you get those results from that data.
    4. Would we also be able to add a date bind value. Lets say, if the user selects start date as may, 1st, 2012 and end date as jun5th. It sort of shows the same data but in weekly format for the weeks between the period selected?Sure, just use those values in a WHERE clause. The output needs to have a fixed number of columns, however. Say that number is 14. You can give a range that only covers 5 weeks, but the output will have 9 0's at the end of every row. You can give a range that covers 15 or more weeks, but the weeks after 14 will not be shown. To get around that requires dynamic SQL (if you want each week in a real column) or string aggregation. See {message:id=3527823}
    Point 3 is different from point 1 as in, the first one would be maybe using your logic but hardcoding for 14 weeks. Point three would be a little more dynamic.
    Thanks for your time.
    Sun
    Edited by: sun1977 on Jun 7, 2012 2:28 AM
    EXEC  :start_dt_txt := '01-May-2012';
    EXEC  :end_dt_txt   := '05-Jun-2012';
    WITH  got_week_num  AS
         SELECT  col1, col2
         ,     1 + FLOOR ( (col2 - TO_DATE (:start_dt_txt, 'DD-Mon-YYYY'))
                         / 7
                     )     AS week_num
         FROM    t
         WHERE     col2     >= TO_DATE (:start_dt_txt, ':DD-Mon-YYYY')
         AND     col2     <  TO_DATE (:end_dt_txt,   ':DD-Mon-YYYY') + 1
    SELECT       col1
    ,       COUNT (CASE WHEN week_num =  1 THEN 1 END)     AS week_1
    ,       COUNT (CASE WHEN week_num =  2 THEN 1 END)     AS week_2
    ,       COUNT (CASE WHEN week_num =  3 THEN 1 END)     AS week_3
    ,       COUNT (CASE WHEN week_num =  4 THEN 1 END)     AS week_4
    ,       COUNT (CASE WHEN week_num =  5 THEN 1 END)     AS week_5
    ,       COUNT (CASE WHEN week_num =  6 THEN 1 END)     AS week_6
    ,       COUNT (CASE WHEN week_num = 14 THEN 1 END)     AS week_14
    FROM       got_week_num
    GROUP BY  col1
    ORDER BY  col1
    ;Edited by: Frank Kulash on Jun 7, 2012 5:53 AM

  • Grouping data based on period in a Pie Chart

    Version 4.1/11g
    Hi There,
    I have a Pie chart to create which basically should be based on three parameters, Error code, count(of errors) every month. The Pie chart accepts only two parameters so I have the error code and count. Was looking to also have something based on period, as in every month. Would running the chart for every month be the only option? Never used the 3d Stacked option. Can that be used for basically to show the number of errors every month grouped by error code?
    SELECT       errorcode
    ,       TRUNC (col2, 'MONTH')     AS month
    ,       COUNT (*)              AS n
    FROM       table_x
    GROUP BY  col1
    ,            TRUNC (col2, 'MONTH')
    ;Thats the normal sql query which would get the data. But was looking at using a graphical chart for the same.
    Any ideas?
    Thanks,
    Sun

    Sun,
    Here is a great site to stimulate your charting ideas.
    [url http://apex.oracle.com/pls/apex/f?p=36648:LOGIN]Sample Charts, Maps, Gantts and Trees
    Jeff

  • Query to group by based on partial count match

    Dear experts,
    Here is a challenge question.
    I have a table a on Oracle 11i – this is how it is defined.
    desc a
    Name Null Type
    STORE_NUMBER NOT NULL CHAR(9)
    ASSORTMENT_NUMBER NOT NULL CHAR(9)
    ITEM_NUMBER NOT NULL CHAR(9)
    DESCRIPTION CHAR(1000)
    UPC_CODE NOT NULL CHAR(15)
    STOCK_FLAG CHAR(1)
    AVG_RTL_PRICE CHAR(16)
    SALES_MOVEMENT CHAR(16)
    PROD_STYLE CHAR(50)
    COLOR CHAR(50)
    ATT_1 CHAR(50)
    ATT_2 CHAR(50)
    ATT_3 CHAR(50)
    ATT_4 CHAR(50)
    ATT_5 CHAR(50)
    ATT_6 CHAR(50)
    ATT_7 CHAR(50)
    ATT_8 CHAR(50)
    ATT_9 CHAR(50)
    ATT_10 CHAR(50)
    ATT_11 CHAR(50)
    ATT_12 CHAR(50)
    ATT_13 CHAR(50)
    ATT_14 CHAR(50)
    ATT_15 CHAR(50)
    25 rows selected
    Primary Key as Store_number, Assortment_number, item_number. Therefore, for a particular assortment number, one store will have no two records of the same item_number.
    Now, I want to add some more custom conditions to my extract from this table; we are doing this manually on an xls file by applying some formula. Wondering if we can do this by a sql query.
    Here are the conditions –
    1.     From table a, for any particular assortment_number, count of items belonging to a store. E.g –
    Count of items     Store_number
    5     1011
    7     1022
    23     1033
    12     1044
    2.     This is more challenging. From table a, for stores with the same count of item_numbers, list down the store numbers which have the same count of items and same items in the set under them. E.g – as below.
    Count of items     Store_number     Item_number     Match Indicator     Matching Stores
    5     3     123|12|1234|12|1     N     
    5     24     123|123|123|123|123     Y     22|234
    5     21     123|451|2341|234|5100     N     
    5     22     123|123|123|123|123     Y     24|234
    5     456     123|12|1|2|3     N     
    5     234     123|123|123|123|123     Y     22|24
    3     45     12|123|12     Y     222|150
    3     432     21|34|56     Y     123
    3     222     12|123|12     Y     45|150
    3     123     21|34|56     Y     432
    3 150 12|123|12 Y 45|222
    The above table may get positions shifted to its left due to formatting.
    Appreciate your time and effort.
    Thank You.

    create table tmp_storeaggbyitem as
    select
    ltrim(trim(a.store_number),0) as store,
    ltrim(trim(a.item_number),0) as item
    from guide_pog_item_mstr a
    where ltrim(trim(a.assortment_number),0) = '25571'
    )Sample data in the table looks like this -
    Store          Item
    49               59310
    49               59315
    49               59114
    49               59295
    63               59310
    63               59315
    63               59314
    63               59308
    138             59310
    138             59315
    138             59114
    138             59295
    174             8399
    174             6132
    174             6129
    174             6137
    174             6175
    270             8399
    270             6132
    270             6129
    270             6137
    270             6175
    343             8399
    343             6132
    343             6129
    343             6137
    343             6175Here is the result set I am looking for -
    Store        Count of Items        Item                                                   Matching Stores
    49                    4                 59310|59315|59114|59295                    49|138    
    63                    4                 59310|59315|59314|59308                    None
    138                  4                 59310|59315|59114|59295                    49|138
    174                  5                 8399|6132|6129|6137|6175                   174|270|343
    270                  5                 8399|6132|6129|6137|6175                   174|270|343
    343                  5                 8399|6132|6129|6137|6175                   174|270|343
    .....Which version of the database are you using? The LISTAGG fucntuion (which is avaialble in Oracle 11.2, but not in 11.1) might be helpful here.
    >
    We are using Oracle Enterprise Edition 11.2.0.1.0 - 64 bit
    Pl/Sql release 11.1.0.1.0
    >
    Why are you using the CHAR datatype instead of VARCHAR2? It may have nothing to do with this prolem, but it will cause other problems.
    >
    Agreed. I asked the same to my design team I inherited this table from. We are working out on the new table soon.
    Thanks, Sanders.

  • How to group data based on date

    In my program the internal table is returning several values based on date.
    for example for the first pernr in the image below  there are four records. i need to delete the first record which is between the dates 20 and 30 .
    and also i need to get the difference between the dates as the record 23 and 28  i need to get separate dates as 24, 25..28.

    I am not sure if I understood your question correctly.
    From what I have understood, you can use the following logic.
    This logic will move all the records from lt_fields2 to another table lt_fields1 with begda between 20 and 30 of any month, except for the first record. It will also move records for every date between begda and endda of each record.
    You can alter the logic based on your exact requirement.
    declare another table lt_fields1 like lt_fields2.
    data del_flag.
    data prev_month(2) type c.
    sort lt_fields by pernr begda.
    clear del_flag.
    loop at lt_fields2 into wa_fields where begda+6(2) GE 20.
    * Delete the first record having date greater than 20 in a month for each pernr.
       at new pernr.
            clear del_flag.
       endat.
       if begda+4(2) NE prev_month.
           clear del_flag.
      endif.         
        if del_flag is initial. 
            del_flag = 'X'.
            continue.  " This record will not be moved to the final internal table.
       endif.
    * Add records for each date between begda and endda.
       append wa_fields to lt_fields1.
       prev_month = begda+4(2)
       while wa_fields-begda LT wa_fields-endda.
             wa_fields-begda = wa_fields-begda+1.
             append wa_fields to lt_fields1.
       endwhile.
    endloop.

  • How to optimize query that returns data based on one matching and one missing field joining two tables

    Hi all,
    Here is what I am trying to do. I have 2 tables A and B. Both have a fiscal year and a school ID column. I want to return all data from table B where all school IDs match but fiscal year from A is not in B. I wrote 2 queries below but this took
    2 minutes each to process through 30,000 records in table B. Need to optmize this query.
    1) select 1 from table A inner join table B
    on A.SchoolID=B.SchoolID where A.Year not in (select distinct Year from table B)
    2) select distinct Year from Table A where School ID in (select distinct School ID from table B
    and Year not in (select distinct Year from table B)

    Faraz81,
    query execution time will depend not only on your data volume and structure but also on your system resources.
    You should post your execution plans and DDL to generate data structures so we can take a better look, but one think you could try right away is to store the results of the subquery in a table variable and use it instead.
    You'll also benefit from the creation of:
    1. An index for the B.SchoolID column.
    2. Statistics for the Year column in table B.
    You can also try to change the physical algorithm used to join A to B by using query hints (HASH, MERGE, LOOP) and see how they perform. For example:
    select 1 from table A inner HASH join table B
    on A.SchoolID=B.SchoolID where A.Year not in (select distinct Year from table B)
    As the query optimizer generally chooses the best plan, this might not be a good idea though, but then again, without further information its going to be hard to help you.

  • Query to Group records based on

    Hello,
    I need a help.
    I have a errortable with 4 columns (pk, errordate, activestatus, errormsg). I need to get a count of the records with a pattern of errormsg but im getting lost on this, not sure where is the problem.
    For example there are records with errormsg column which has logged some error msgs like say
    'xxxIn-Housexxx'
    'yyyCheckedInyyy',
    aaaIn-Hoouseaaa',
    bbbCheckedInbbb'
    I'm only interested to have a count of all those with the pattern match of 'In-House' and 'CheckedIn'
    this is the one i was trying, which is giving me some syntax error not sure what it is
    select count(*) from error_table where errordate > sysdate - 3
    group by errormsg
    having
    errormsg like '%In-House%'
    or
    errormsg like '%CheckedIn%'
    I'm really confused to get a working sql for this. can you please help me.
    thanks

    select sum(case
                   when upper(errormsg) like '%IN-HOUSE%' then 1
                   else 0
               end
              ) in_house_error
          ,sum(case
                   when upper(errormsg) like '%CHECKEDIN%' then 1
                   else 0
               end
              ) checkedin_error         
    from   error_table
    where  errordate > sysdate - 3
    ;

  • Looking for formula to fill dates of particular days of week for a given month

    Hi
    I have a Numbers document with a sheet for each month of the year, named "January", "February", "March", etc.
    Each sheet contains a table as follows:
    I am looking for a function that will calculate the dates in a given month that I am due to see each client, based on the year (contained in a single cell table on a seperate sheet) and the month of the sheet (I am presuming that a function can refer to the name of a sheet).  These dates would populate the cells under "Session 1", "Session 2", etc. (for some days of the week there may be only four sessions, for others five).
    I hope this is clear, and would be grateful for any help in getting this working.
    Thanks,
    Nick

    Here's an example, using September, 2011 as the month.
    Main Table:
    A1: =DATE(Year :: A2,9,1)
    This calculates the Date and Time value for midnight at the beginning of the first day of the ninth month of the year indicated in cell A2 of the table "Year" (September 1, 2011). It uses a Custom format to display only the month and year of this date. The Dates calculated in the rest of the table depend on the Date and Time value in this cell.
    A2 - A11: Entered data. Not used in calculations.
    B2 - B10: Entered data. The text values here are used as search-for values, and must match the text values in column A of the table Weekday lookup.
    C2, Filled down to C10: =$A$1+MOD(7-WEEKDAY($A$1)+VLOOKUP(B,Weekday lookup :: $A:$B,2,FALSE),7)
    This calculates the Date corresponding to the first occurrence of the weekday indicated in B during the month in A1. The result is a Date and Time value (used in formulas to the right). The cells use a custom format to display only the Day (of the month) number.
    D2, Filled right to column F and down to row 10: =C+7
    Calculates the date seven days after the date in column C.
    G2, filled down to row 10: =IF(MONTH($A$1)=MONTH(F+7),F+7,"")
    This is the same formula as used in D2, but adds a check to suppress the calculation if the result is not in the same month as other dates on the table.
    Year: The requested single cell table to record the year.
    Weekday Lookup: A lookup table from which to retrieve the weekday number for the day in column B of the main table.
    Custom formats:
    Select cells C2 - G10
    Open the Inspector > Cell Format Inspector > Date and Time
    Delete the unwanted elements from the workspace in the Inspector.
    Repeat for cell A1.
    Regards,
    Barry
    PS: Numbers cannot use the Sheet name or Table name as data for a formula unless the name is placed into a cell on a table.
    B

  • Execute Different SQL Statements Based On Day of Week

    I need to execute different sql statements based on the day of the week in Oracle 8i. In SQL Server, it's pretty simple. SELECT
    CASE DATEPART(dw,GETDATE())
    WHEN 4 THEN (SELECT COUNT(*) FROM ADR_VLDN )
    END
    In Oracle it should be something like this
    IF to_char(SYSDATE, 'D') = 2 THEN
    SELECT * FROM RSVP_FILE_PRCS WHERE ROWNUM = 1;
    ELSEIF to_char(SYSDATE, 'D') = 3 THEN
    SELECT * FROM RSVP_FILE_PRCS WHERE ROWNUM = 2;
    END IF;
    But this doesn't work. Does anyone have any ideas about how to do this in Oracle?

    805771 wrote:
    Yes, but I don't want to create 7 different jobs, one for each day of the week. Isn't there a way to do this in PL/SQL? It took me 10 seconds in SQL Server's TSQL.Yes you keep showing some TSQL syntax that obviously does not do what you are asking for.
    >
    SELECT
    CASE DATEPART(dw,GETDATE())
    WHEN 4 THEN (SELECT COUNT(*) FROM ADR_VLDN )
    ENDSo the equivalent in Oracle would be
    SQL> var n number
    SQL> begin
      2    if to_char(sysdate,'D') = '4' then
      3      select count(*) into :n from dual;
      4    end if;
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL> print n
             N
             1Also takes 10 seconds.

  • Grouping Data on DVT Component

    Dear All,
    I have been thinking about this for sometime..
    The DVT Area graph is excellent component that displays spikes of
    data.
    <dvt:areaGraph id="areaGraph1" subType="AREA_VERT_ABS" tabularData="#{myBean.tableData}">
         <dvt:background>
           <dvt:specialEffects/>
         </dvt:background>
         <dvt:graphPlotArea/>
         <dvt:seriesSet>
           <dvt:series/>
         </dvt:seriesSet>
         <dvt:o1Axis/>
         <dvt:y1Axis/>
         <dvt:legendArea automaticPlacement="AP_NEVER"/>
    </dvt:areaGraph>However I have a requirement to group the data based on day.
    When I have a sample date data like below, all of these are displayed on the x-axis.
    My web service returns data on a 6hour period per day
    2011-01-01 00:00    *(Note: 12AM)*
    2011-01-01 06:00     *(Note: 6AM)*
    2011-01-01 12:00     *(Note: 12PM)*
    2011-01-01 18:00     *(Note: 6PM)*
    2011-01-02 00:00
    2011-01-02 06:00
    2011-01-02 12:00
    2011-01-02 18:00
    2011-01-05 00:00
    2011-01-05 06:00
    2011-01-05 12:00
    2011-01-05 18:00But my requirement is, can I optionally group the data so that it will only display
    the date on the x-axis but still maintains the variation on the time.
    Say, the x-axis of the graph would only display the day variations
    2011-01-01 00:00
    2011-01-02 00:00
    2011-01-03 00:00
    2011-01-04 00:00
    2011-01-05 00:00I tried my best to explain it in detail but I would be more than willing to supply more information.
    Thanks.

    Can you provide a screenshot of the results that you're seeing?
    My guess here is that your data isn't triggering the built in time axis behavior. When java.util.Date objects as passed to the graph, it should automatically convert to a time axis that is able to optimize the label behavior (providing label display at optimized intervals). The screenshot will help confirm and we can figure out the solution from there.

  • Filtering View Data Based on Location Value

    Hi,
         I have a mangers view in my list.
    we have some cluster values like this:
    AP/AU/MK
    BD/CO/EN/MV
    BE/CR/LH
    BO/KM/KG
    BP/BU/GR/WC
    DM/KT/WM
       I wrote CAML query for fetching data based on filter condition(i.e. Cluster value)
    <Query>
    <Where>
    <Eq>
    <FieldRef Name="Cluster"/>
    <Value Type="Text">AP/AU/MK</Value>
    </Eq>
    </Where>
    </Query>
       But i getting only "AP/AU/MK" cluster data only.I want manuvally w/o hot coding cluster value.
    Help me.
    Thanks

    Hi,
         I wrote that code in SharePoint designer under <Query>
    Now i am able to filter AP/AU/MK cluster data.Because i hotcode AP/AU/MK cluster in Query.
    <Query>
    <Where>
    <Eq>
    <FieldRef Name="Cluster"/>
    <Value Type="Text">AP/AU/MK</Value>
    </Eq>
    </Where>
    </Query>
        if again i want BE/CR/Lh cluster data.i need to change that query. i don't want like that. we want manuvally
    thanks:

Maybe you are looking for

  • "Bottom" Setting not sticking in print calibration

    Is anyone else noticing that in the print dialog if you have set the Bottom calibration it won't "stick" for long? In my case it ends up reverting to zero across sessions. And I wonder why iPhoto can print to my HP printer/paper without calibration b

  • Connecting Tivo To Time capsule

    I am trying to set up a network so that I can look photos and listen to music on my new home a/v system. I have an iBook as my primary computer. It backs up to the time capsule. I have a Tivo and the TIvo desktop software. Can anyone give advice or p

  • Pagination after executequery with a dynamic where clause

    Hi all, I have a problem with pagination after setting a where clause dynamically and performing an executequery in ViewObjectImpl.java. As a result of this, the amount of records are decreased returned by the viewobject, however the pagination is no

  • When I first start up computer and click on Safari, a blank page appears. I am trying to make MY MSN as the opening page. How do I do this? Thanks for any help.

    When I first turn on my computer and click Safari, a blank page appears. I use to have MY MSN as the opening page on Safari. Don't know what happened, but how do I restore it back to the way it was? I've tried everything, I know it has to be somethin

  • EJBs in WebApp

    Hello, I'm deploying a Servlet that calls a generic utility class which returns the LocalHome interface of a Session EJB. The utility class and sesion interface classes are in .jar files within the WebApp. The Servlet is declared in web.xml, but coul