average amount of an article during the days of the week to a month

Dear members,

I want an application that compiles the data as below.

Point 1 first day of the week saying Monday by 10 in a specific month

Article 1 Monday next 20th of the same month qty

Article 1 Monday 25th of the same month next qty

Article 1 Monday next 22nd of the same month qty

If there are 4 four Mondays of the month

the avg of 1 article is (10 + 20 + 25 + 22) / 4 = 19.25

Similarly, avg of article 2, point 3, point 4. .on every Monday, Tuesday, Wednesday... for a month.

kindly show me the way...

Thank you.

teefu

Lahore.

Hi teefu,

Try this

create table ts1

(sale_date date, item_code number, number of qty_sold);

Insert the ts1

values (to_date('02-Jun-2014','DD-mon-YYYY'), 1, 10);

Insert the ts1
values (to_date('16-Jun-2014','DD-mon-YYYY'), 1, 20);

Insert the ts1
values (to_date('23-Jun-2014','DD-mon-YYYY'), 1, 30);

Insert the ts1
values (to_date('23-Jun-2014','DD-mon-YYYY'), 1, 25);

Insert the ts1
values (to_date('30-Jun-2014','DD-mon-YYYY'), 1, 30);

Insert the ts1
values (to_date('02-Jun-2014','DD-mon-YYYY'), 1, 10);

Insert the ts1
values (to_date('05-Jun-2014','DD-mon-YYYY'), 1, 70);

Insert the ts1
values (to_date('12-Jun-2014','DD-mon-YYYY'), 1, 150);

Insert the ts1
values (to_date('26-Jun-2014','DD-mon-YYYY'), 1, 40);

Select item_code, to_char(sale_date,'Day') day, avg (qty_sold) avg_sold

ts1 by item_code group, to_char (sale_date, 'Day')

output

ITEM_CODE DAY AVG_SOLD

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

1 Monday 19,25

1 Thursday 86.666667

Select the day of item_code, to_char (sale_date, 'Day'),

Sum (qty_sold) wheel (TO_NUMBER (to_char (sale_date, 'w'))) avg_sold

of ts1

Item_code group, to_char(sale_date,'Day');

ITEM_CODE DAY AVG_SOLD

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

1 Monday 15.4

1 Thursday 65

Tags: Database

Similar Questions

  • Days of the week in a month

    I want to get every day of the week in a month.
    I mean I have beteen date setting
    from 12/01/07 to 31/07/12
    and I need every day of the week between these dates.

    Please tell me how?

    Hey Ghulam,

    I want to get every day of the week in a month.

    Query:

    SELECT     TRUNC (SYSDATE, 'MONTH') + LEVEL - 1 the_date,
               TO_CHAR (TRUNC (SYSDATE, 'MONTH') + LEVEL - 1, 'Dy') dt
          FROM DUAL
         WHERE TO_CHAR (TRUNC (SYSDATE, 'MONTH') + LEVEL - 1, 'Dy') NOT IN
                                                                   ('Sat', 'Sun')
    CONNECT BY LEVEL <= LAST_DAY (SYSDATE) - TRUNC (SYSDATE, 'MONTH') + 1;
    

    Thank you
    Shankar

  • During the week to Daily Record Explosion?

    Hello

    I'm looking for a way to take a set of documents stamped with a weekend date and explode in a recordset for each day of this week. The data of the entire file would be identical, except for the date column. Here is an example.
    item_id  week_end_date   some_value
    1        2009-12-05      5
    1        2009-12-12      10
    1        2009-12-19      15
    2        2009-12-05      20
    2        2009-12-12      25
    2        2009-12-19      30
    What I want on the other end is something like this (I'll do only the first two records from above). I put an asterisk on the 'source' folder
    item_id  week_end_date   some_value
    1        2009-11-29      5
    1        2009-11-30      5
    1        2009-12-01      5
    1        2009-12-02      5
    1        2009-12-03      5
    1        2009-12-04      5
    1        2009-12-05      5*
    1        2009-12-06      10
    1        2009-12-07      10
    1        2009-12-08      10
    1        2009-12-09      10
    1        2009-12-10      10
    1        2009-12-11      10
    1        2009-12-12      10*
    I know I could do with a PL/SQL loop, but I am interested in more than one pure solution of SQL.

    My thought was to do a temp of sorts with 7 rows table and a column. It would basically be numbers between 0 and -6. Then in my SQL I assemble and simply add the value of the temporary table to the week_end_date blew up the records on. I would like to know if I'm crazy or on the right track. If I'm heading in the right direction, I would need a little help with the implementation.

    Thanks in advance.

    Hello

    Welcome to the forum!

    You have the right idea, with a table 7-row 1-column, but there is no need to create an actual table.
    You can use a subquery, as cntr below, created within the application itself and then join the result set of the subquery as if it were a table:

    WITH     cntr     AS
    (
         SELECT     LEVEL - 1     AS n
         FROM     dual
         CONNECT BY     LEVEL <= 7
    )
    SELECT     item_id
    ,     week_end_date - n     AS a_date
    ,     some_value
    FROM          table_x
    CROSS JOIN     cntr
    ;
    

    In Oracle, it is rarely necessary to create temporary tables.

  • Request: keep view zoomfactor during the week (and a day)

    Dear developers,

    I started using the calendar stock Sony having been confronted with the awful Google Calendar 'facelift', which went from great to unusable in one day!
    When the pinch of hours to have a better overview a blow to another week resets the zoom set :'(

    C6903 14.4.A.0.157
    Calendar 14.3.A.1.2

    Try contacting Sony Xperia support, about that.
    http://support.sonymobile.com/global-en/contactus/

  • Get number of days of the week to a month

    Hi, someone can tell me how to get the number of working days per month, or the number of days other than Saturdays and Sundays

    Well, others and I already posted an example of use of sysdate?

    Maybe you need to take a look at this again.

    Just trunc sysdate to month: trunc (sysdate, 'mm') = 06/01/2009
    Take the start of the next month less a day: trunc (add_months (sysdate, 1), 'mm')-1 = 30-06-2009 (or use last_day)

    Use a connection level, count the days without the Treaty, and there you go...

  • Updated tables during the weekly load?

    All,
    We are running Oracle 10 g. We try to identify the tables that updated operating expenses of our weekly or monthly. I did Internet searches including this forum, but have not yet found anything useful. I tried the trigger option; It works, but increases significantly at run time. For example, a stored procedure that would run between 1-2 minutes to load approximately 6 500 lines, it took 12 minutes to complete. For the moment, our weekly workload runs in about 7 hours. I predict adding triggers for selected tables drastically increases at run time. I also check the most recent row id won't help with updates and deletions. In addition, the following code works fine when running in Oracle 10 g personal edition, but when running in the development environment, it fails.
    select scn_to_timestamp(ora_rowscn) from EMPLOYEE;
    ORA-08181: the specified number is not a number of regime change in force
    ORA-06512: at "SYS." SCN_TO_TIMESTAMP', line 1



    Are there other options other than what I've listed above in order to detect when a table is updated of our weekly load process?



    Thanks in advance,


    Seyed

    All chastise you for instrumentation does not is correct, but the other option you have "explored" failed because you do not quite understand it.

    Ora_rowscn, is a pseudo column that returns either the RCS of the last change to the block or rank, depending on how the table has been set. The SCN_TO-TIMESTAMP function throws this SNA at a table to perform the conversion. No each NPC is here, I think that the rule is the last fortnight of SNA are there, obviously depends on many variables.

    Your selection did this look upward to the entire table. The "early" lines probably have not been affected over the years, SNA of these blocks have long aged out of the system table. In addition, you don't have the RCS for EACH line, just the last of them has changed.

    Here's how you can use it.

    build a table with three columns (table_name, pre_load_SCN, Post_load_SCN)... before run you out of the lot, which fills with the MAX (Ora_rowscn) of each table. Execute the batch, update of this table with the MAX (Ora_rowscn) still once and for all the tables, a table that does not at least had a line changed since the date of your first analysis.

    Problem: Could be any process, not just the batch. So if you know, NOTHING else is running... you might be sure that you have captured the list of modified tables.

  • The list of the days of the weeks

    Hi all

    I have the following query which list weekdays between two dates

    select to_char(to_date('13/03/2014','dd-mm-yyyy') + rownum -1, 'DAY')
    from all_objects
    where (rownum <= to_date('18/03/2014','dd-mm-yyyy')-to_date('13/03/2014','dd-mm-yyyy')+1);
    
    

    The results:

    THURSDAY
    FRIDAY
    SATURDAY
    SUNDAY
    MONDAY
    TUESDAY

    now, it lists every day of the week...

    How can I add the query to eliminate the weekends (Friday and Saturday in my country)

    I want it to be as follows:

    THURSDAY
    SUNDAY
    MONDAY
    TUESDAY

    Best regards.

    Try this

    SELECT week

    (Select to_char (to_date (' 13/03/2014 ','dd-mm-yyyy') + rownum-1, 'DAY') during the week)

    of object

    where (rownum<=>

    WHERE the trim (weekday) not in ('SATURDAY ', 'SUNDAY');

  • 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}

  • Ways to put the application in read-only during the monthly maintenance mode

    Hello

    We have a situation where, during the maintenance phase every month for 2 or 3 days, I need to put the application in read mode only. We already have the dimension security level applied to each user, but even to users who have write access to certain members on the forms of data etc., the app just can't be read only during this period so that no user can enter data.

    I know the application in maintenance mode, all users will be be locked is not what we want. Users should always be able to see the dataforms, reports, etc. So, please let me know your ideas on this.

    Any ideas are appreciated.
    ~ Hervé

    The same question was asked the other day - How can I request a read-only?

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • Add the number of days of the week to date

    Currently I have the following in place, formcalc code which adds a number of days (based on a calculation different field "TotalDays") on a date, but would like for the calculation of the new date to include only during the week.

    Is there a way to do this?

    var begindate = Date2Num (xfa.resolveNode ("SecB\. Date\.4'), "YYYY-MM-DD")

    $= Num2Date (begindate + TotalDays, "YYYY-MM-DD")

    Thank you.

    Hello

    Here is an example which will add figures given from Monday to Friday at your selected date excluding Saturday and Sunday.

    var dp = "MM/DD/YYYY" ; date pattern
    var d = Date2Num($.formattedValue, dp) ; selected date to number
    var p = 9 ; Number of days to add to the selected date
    
    for i = 1 upto p do
              d = d + 1
              while (Num2Date(d, "e") eq 6 or Num2Date(d, "e") eq 7) do
                        d = d + 1
              endwhile
    endfor
    
    DateField2.formattedValue = Num2Date(d, dp)
    
  • Recurring appointment Set for certain days of the week each month in the calendar on Surface RT?

    It seems to me that this is not possible, but is there a way I can put a recurring appointment for a certain day of the week of each month in the calendar on the Surface RT? For example, a meeting Tuesday on two or one excursion each fourth Sunday?  I know that this is possible in Outlook on a PC and I would like to do it on the Surface RT as well.  Most of my recurring appointments are of this type.  When I recur every month on the Surface, it just sets it for the same date (for example the 12th of each month) instead of the second Tuesday.  Thank you!

    Hi Lisa,

    You were correct when you say that 'it seems to me that's not possible. ' The recurring appointment for some day of the week each month in the calendar on Surface RT cannot be done by date and not day.

    Good day!

  • The weekly backup failure

    Hello

    I am running an RMAN backup and daily backups to succeed, but I encounter a problem during the weekly backup.

    I am using recovery Director: Release 11.1.0.7.0

    Here is the script I'm running:

    Run {}

    SQL ' alter session set nls_date_format = "dd-mon-yyyy hh24:mi:ss";

    backup current controlfile;

    Home ' date/t ';

    Home ' time/t ';

    View all;

    outline report;

    cross-checking of backup;

    overlap archivelog all;

    duplication of copy of the controlfile;

    Home ' date/t ';

    Home ' time/t ';

    delete noprompt force backup expired;

    delete noprompt obsolete force;

    delete noprompt force expired archivelog all;

    delete noprompt force archivelog backupset all completed before ' sysdate-2';

    delete noprompt force complete database before backupset ' sysdate-7 ";

    Home ' date/t ';

    Home ' time/t ';

    retrieve the copy of the database with the tag "FULL";

    backup as backupset compressed incremental level 1 to retrieve copy with 'FULL' tag data include current controlfile;

    SQL 'alter system archive log current;

    SQL 'alter controlfile backup database to trace";

    ARCHIVELOG backup all the tag delete 'ARCHIVELOG' entry;

    Home ' date/t ';

    Home ' time/t ';

    }

    "exit";

    The question starts with the recover command.

    The errors I get:

    From back to January 27, 14

    using channel ORA_DISK_1

    using the ORA_DISK_2 channel

    channel ORA_DISK_1: from additional data file from the restore backup set

    channel ORA_DISK_1: specifying data file copies to recover

    retrieve the file number of the data copy = 00003 name = E:\FLASH_RECOVERY_AREA\NNVSDB\DATAFILE\O1_MF_UNDOTBS1_9CMHHTNM_ file. DBF

    retrieve the file number of the data copy 00005 name = E:\FLASH_RECOVERY_AREA\NNVSDB\DATAFILE\O1_MF_TS_NSA_D_9CMHHTNM_ = file. DBF

    retrieve the file number of the name 00006 = copy data file is E:\FLASH_RECOVERY_AREA\NNVSDB\DATAFILE\O1_MF_TS_NSA_D_9CMHY34C_. DBF

    retrieve the file number of the data copy = 00009 name = E:\FLASH_RECOVERY_AREA\NNVSDB\DATAFILE\O1_MF_TS_NSA_L_9CMHRGCG_ file. DBF

    channel ORA_DISK_1: backup E:\FLASH_RECOVERY_AREA\NNVSDB\BACKUPSET\2014_01_25\O1_MF_NNND1_TAG20140125T020010_9G72SC4V_ piece reading. BKP

    channel ORA_DISK_2: from additional data file from the restore backup set

    channel ORA_DISK_2: specifying data file copies to recover

    retrieve the file number of the data copy = 00001 name = E:\FLASH_RECOVERY_AREA\NNVSDB\DATAFILE\O1_MF_SYSTEM_9CMHY42C_ file. DBF

    retrieve the file number of the name 00002 = copy data file is E:\FLASH_RECOVERY_AREA\NNVSDB\DATAFILE\O1_MF_SYSAUX_9CMHYXN3_. DBF

    retrieve the file number of the data copy 00004 name = E:\FLASH_RECOVERY_AREA\NNVSDB\DATAFILE\O1_MF_USERS_9CMHZ2T6_ = file. DBF

    retrieve the file number of the data copy 00007 = E:\FLASH_RECOVERY_AREA\NNVSDB\DATAFILE\O1_MF_TS_NSA_I_9CMHRGCG_ name = file. DBF

    retrieve the file number of the data copy 00008 name = E:\FLASH_RECOVERY_AREA\NNVSDB\DATAFILE\O1_MF_TS_NSA_I_9CMHW21Q_ = file. DBF

    channel ORA_DISK_2: reading from the backup E:\FLASH_RECOVERY_AREA\NNVSDB\BACKUPSET\2014_01_25\O1_MF_NNND1_TAG20140125T020010_9G72SC3W_ piece. BKP

    RMAN-00571: ===========================================================

    RMAN-00569: = ERROR MESSAGE STACK FOLLOWS =.

    RMAN-00571: ===========================================================

    RMAN-03002: failure of the command recover at 27/01/2014 05:09

    ORA-19870: error when restoring the backup E:\FLASH_RECOVERY_AREA\NNVSDB\BACKUPSET\2014_01_25\O1_MF_NNND1_TAG20140125T020010_9G72SC4V_ piece. BKP

    ORA-19625: error identifying file E:\FLASH_RECOVERY_AREA\NNVSDB\DATAFILE\O1_MF_UNDOTBS1_9CMHHTNM_. DBF

    ORA-27041: could not open the file

    04002 - OSD: could not open the file

    S/O-error: (OS 2) the system cannot find the file specified.

    What I am doing wrong?

    Thanks in advance.

    You use an incremental update strategy of backup.  This attempts to update the full backup on the disk.  The error here is that the data UNDOTBS1 file is NOT in the database backup on the disk (in the FLASH_RECOVERY_AREA).  Bottom line: all your backups are useless without this data file in the backup.

    See gradually "update backup" to http://docs.oracle.com/cd/B28359_01/backup.111/b28270/rcmbckba.htm#CHDEHBFF

    (Frankly, your script is a mixture of different configurations!)

    Hemant K Collette

  • How to get the old data 6 months from the current date?

    Hi friends,

    I have a table which includes historical data, which are having more than 1 years old data. The historical table gets updated once a week. My requirement is that I should get the latest data from the week of each month for 6 months according to the current data. I use oracle 10g.

    Can you please someone help in this.

    Thanks in advance

    SELECT last_day (ADD_MONTHS (TRUNC (SYSDATE, 'mm'),-LEVEL))-7 start_dt.
    LAST_DAY (ADD_MONTHS (TRUNC (SYSDATE, 'mm'),-LEVEL)) end_dt
    OF THE DOUBLE
    CONNECT BY LEVEL<=>

    change as a result, I have provided you the start and end dates for your logic...

  • dc5800 Small Form Factor: dc5800 closes during the night or during the day

    My dc5800 Small Form Factor has been stop under its own when not in use, for example during the day or night. When I restart, I get the black screen where it asks if I want to start normally or in safe mode. After startup, it asks if I want to find a solution to the problem (which does not return anything). It never happened while I use the computer. He did periodically, but lately, it's every day. Help?

    Solved the problem by changing some power settings. for example the definition of disk hard do not stop, pc to never sleep, etc.

    You don't know if it's a good thing or not, but the computer turns off when I'm not using it.

  • Why my laptop wireless computer connect to the internet first thing in the morning and late at night, but not during the day.

    I wonder if you can help me please?

    I have problems with my satellite internet access on my laptop wireless.  He beautifully connects to the router and the signal is excellent. However, I'm unable to connect to the internet.  I can use the laptop first thing in the morning because it connects right away, but I would say that 95% of the day I can't use it at all.  Sometimes it will work later in the evening.  I learned this could be due to the intensity of the signal and that some suppliers to fall during the day.  My desk top connects perfectly (if the weather permits it) but is not on the wireless network.  I had no problem with my laptop when I used my previous service provider.  It becomes more frustrating that the inability to use the internet visited my lap top unnecessary.  I can't use it on my neighbors wireless network no problem at all but they we internet different provider.  Can you please help because I don't know why it works first thing in the morning and sometimes late at night, but not during the day?  No matter where the lap top is the first thing in the morning, it will work even if it is forty feet away.  I can sit during the day with my phone right by my router and it still not connect to internet even though the router signal strength is excellent and desktop is on the internet.  Any help would be great, because it leads me into the wall!  I am using WIndows 7 on my lap top from acer.

    Kind regards

    Julie

    I would like to thank everyone for their help with my question.  I can tell you now that I have it solved and I'm pretty embarrassed to say the least.  Following a change of internet service provider, I put a cable into the wrong port on the router... silly me!  It works perfectly now. Thank you once again.

Maybe you are looking for