Summary by weeks

I would like to get the number of invoice based on the status of the invoice for each week during a given month. Here it is the expected result for the month of Jan-2015. Last week County is not printed if the overlap the week another wee i.e. 26/01/15 to 01/02/2015 and one week always start from Monday to Sunday.

sample.PNG

Education creation and insertion of sample table is given below

CREATE TABLE temp_week

(

invoice_id NUMBER (4),

inv_status VARCHAR2 (10),

inv_date DATE

);

INSERT INTO temp_week

VALUES (1000, 'Approved', TRUNC (SYSDATE, 'MM') - 10);

INSERT INTO temp_week

VALUES (1001, 'Pending', TRUNC (SYSDATE, 'MM') - 8);

INSERT INTO temp_week

VALUES (1002, "Transformed", TRUNC (SYSDATE, 'MM') - 7);

INSERT INTO temp_week

VALUES (1003, 'denied', TRUNC (SYSDATE, 'MM') - 5);

INSERT INTO temp_week

VALUES (1004, 'Approved', TRUNC (SYSDATE, 'MM') - 20);

INSERT INTO temp_week

VALUES (1005, 'Approved', TRUNC (SYSDATE, 'MM') - 25);

INSERT INTO temp_week

VALUES (1006, 'denied', TRUNC (SYSDATE, 'MM') - 26);

INSERT INTO temp_week

VALUES (1007, "Transformed", TRUNC (SYSDATE, 'MM') - 32);

This is the query that I worked on but don't know how to get the 'week' in each row of the column because can not use PIVOT() since the beginning and end of the week of a month is not static.

WITH T

-get the start of the week and the end of the week for a given month

     -- https://community.Oracle.com/thread/3670488

AS (SELECT TRUNC)

ADD_MONTHS (TO_DATE (: P_DATE, ' MM/DD/YYYY'), LEVEL - 1).

'IW')

SW1

OF THE DOUBLE

CONNECT BY LEVEL < = 1).

TT

AS (SELECT SW1, / * start of week 1 * /)

SW1 + 6 EW1, / * end of week you 1 * /.

SW1 + 7 SW2,

SW1 + EW2 13,

SW1 + 14 SW3,

SW1 + EW3 20,

SW1 + 21 SW4,

SW1 + 27 EW4,

CASE

WHEN (SW1 + 34 > LAST_DAY (SW1 + 6)) THEN NULL

ANOTHER SW1 + 28

END

'SW5', - so "weekend" is superimposed on the next month, feeling empty for SW5

CASE

WHEN (SW1 + 34 > LAST_DAY (SW1 + 6)) THEN NULL

ANOTHER SW1 + 34

END

"EW5' - if 'end of week' is superimposed on the next month, feeling empty for EW5

T)

SELECT inv_status, COUNT (1) COUNTY, week

OF (-it is to get the first week)

SELECT invoice_id,

inv_status,

inv_date,

To_char (sw1, ' MM/DD') | '-' || To_char (ew1, ' MM/DD') week

OF temp_week tw CROSS JOIN tt

WHERE the inv_date BETWEEN sw1 AND ew1)

GROUP of inv_Status of the week

UNION

SELECT inv_status, COUNT (1) COUNTY, week

OF (-it's about getting the second week)

SELECT invoice_id,

inv_status,

inv_date,

To_char (sw2, ' MM/DD') | '-' || To_char (ew2, ' MM/DD') week

OF temp_week tw CROSS JOIN tt

WHERE the inv_date BETWEEN sw2 AND ew2)

GROUP of inv_Status of the week

UNION

SELECT inv_status, COUNT (1) COUNTY, week

OF (-it's about getting the third week)

SELECT invoice_id,

inv_status,

inv_date,

To_char (sw3, ' MM/DD') | '-' || To_char (ew3, ' MM/DD') week

OF temp_week tw CROSS JOIN tt

WHERE the inv_date BETWEEN sw3 AND ew3)

GROUP of inv_Status of the week

UNION

SELECT inv_status, COUNT (1) COUNTY, week

OF (-it's about getting the fourth week)

SELECT invoice_id,

inv_status,

inv_date,

To_char (sw4, ' MM/DD') | '-' || To_char (ew4, ' MM/DD') week

OF temp_week tw CROSS JOIN tt

WHERE the inv_date BETWEEN sw4 AND ew4)

GROUP of inv_Status of the week

UNION

SELECT inv_status, COUNT (1) COUNTY, week

OF (-it's about getting the fifth week)

SELECT invoice_id,

inv_status,

inv_date,

To_char (sw5, ' MM/DD') | '-' || To_char (ew5, ' MM/DD') week

OF temp_week tw CROSS JOIN tt

WHERE the inv_date BETWEEN sw5 AND ew5)

GROUP of inv_Status of the week

Hello

MyOAF wrote:

...

Is it possible to print the days in a week like "12/29-01/04' as the name of column generic, just curious.

Yes, you can do it.

The dynamic SQL help, the number of columns and their names can rely on the data in the table and the run settings.  This involves running the 2 separate queries: 1 just to derive column names and a 2nd interview, with the data of the embedded in 1 query.

Without using dynamic SQL statements, you can do something very close the query I posted in a branch of a trade UNION and something which generates dates in another branch of the same UNION and sort the results of the first line looks like a header.  You always have the generic column names, but your front-end has means to prevent them from display.

Tags: Database

Similar Questions

  • How can I get my weekly summary under my activity other than a popup once per week?

    How to make a copy of my weekly summary under my activity tracker?  I liked seeing the number of steps and miles that I picked up last week, but now I can't find that info again.  She appeared as an alert on my Apple Watch.  When I use the health app on my IPhone there dashboard that says daily/weekly/monthly/year, but does not update with info

    You can check the weekly summary anytime, by opening the Activity.app on the watch.

    From: http://help.apple.com/watch/#/apd3bf6d85a6

    Open the activity on Apple Watch and press firmly on the display until you see the prompt to change your goal to move.

    Now press the 'Weekly summary' button to see the summary.

    You can take a screenshot to save an image of the summary.

  • My activity tracker is stuck on weekly summary, help!

    Wednesday, I check my weekly summary activity on my Apple Watch and he has been stuck there since then. What should I do to get it back to my daily monitoring?

    Hello

    Scroll to the top of the summary and tap in the upper left corner of your screen. (There should be a link here, but even if it is not displayed, you can find this tapping, area of the screen always returns you to the face of the watch).

  • Help! My Apple Watch is stuck on the screen of weekly activity

    Hello

    My Apple Watch is stuck on the screen of the weekly activity. I tried setting down, I tried the button dial spinning and nothing. There is no done either button. Do I let my Apple Watch lose all batteries, or is there a way to solve this problem!

    Hello

    There should be a link to the upper left corner of the screen.

    Even if you don't see (after verifying that you have reached the top of the summary page), try to tap into this area to exit Preview.

  • Summary of resources and Performance empty data?

    Hi guys,.

    I have recently implemented a new host, G9 DL380 running ESX 5.1, 5.1 VSphere which showed already performance data in summary/resources and graphics in the performance section, but in the last two weeks, I noticed his is no longer showing any settings at all.Capture.PNG

    Capture1.PNG

    I did some reading, some say to reboot the host, but I can't afford any downtime with this to be honest. In addition, others have said to check the time that this can cause problems, the system time is fine, but ILO time is an hour out there, but I didn't think it would affect it?

    Anyone would be able to shed light on why its happening? as I said, it worked very well, but obviously not. I'm a very new starter to VMware, so if someone could let me know laymans in terms, that would be great.

    Hope to hear from someone soon

    See you soon

    Paul

    So he did not solve your problem?

  • Summary of the badges are not related correct score?

    Hello

    Did a migration week last in my lab of 5.8 to 6.0. The migration process selves went very smooth. I did a cleanup and checked/changed the auth in the vCenter adapters info.

    Everything seems to work perfectly, and I'm a data grouping of three different vCenters.

    But it seems that the scores on the 'Summary' for DC, Clusters and hosts tab are not correctly calculated. Two of my clusters spread pretty thin resources wise and I ran out of RAM and the drive on one of the clusters. This is clear when you look at the tab 'Analysis' of the object to the title of the resource and time remaning. Notes for the two tabs is 0 (RED).

    Shouldn't the summary score for "Risk" being hit by a very low score ('0') for the remaining capacity and the remaining time? Health and energy efficiency score is also off in my environment. Health is 100, risk 0, Effiency is 100. This is all wrong in my environment and 5,8 reflects the sad and true history on my lab environment ;-)

    Best regards

    Øivind Ekebergtunnellen

    Right answer:

    «Great badges are based is more minor badges as he did in 5.x, which, in your example, the capacity and the remaining time are.» the badge of great 'risk' is driven by risk triggered alerts. »

    Thanks to Maher AlAsfar for the answer.

    So given that the risk consists of not minor badges but risk alerts I propose you go to content-> definitions alert and start learning alerts that might happen and what triggers them.

    Click all filters-> Impact-> risk. Then you can see the 17 built in reports of risk. Edit each of the alerts to learn what triggers the warning symptoms.

    If you look, for example, "Virtual Machine a CPU Contention caused by Co stop" you can see he has 5 triggers of which 3 must be active to trigger the alert.

    BR,

    Monberg

  • A request for information on the 'Summary' cluster tab

    Someone has a powershell script to query the total number of virtual machines and templates in a cluster?

    I'm a heavy load of S-VMotion on a weekly basis, and I want to run a script that can pull the total number of virtual machines in each of the groups within a specific data center.  I need to keep track of speed to get this and again how much I have to do.

    At the moment it's a manual count of the process and I had to script this and then I can automate to send me an email a week.

    Thanks for any help you can provide...

    Hello

    in order to count models and virtual computers on each cluster in VC, you can use this:

    Although I'm not so sure if it's the best way how to do it... I myself am cofused several times while writing this, but...

    $clusters = (get - view - viewtype virtualmachine-filter @{"Config.Template" ="True"}) | %{$_. Summary.Runtime.Host | Get-VIObjectByVIView | get-cluster | fate - the property name} | Group-object - property name

    Get-view viewtype - clustercomputeresource | Select name, @{N = "MV"; E = {(get-vue-viewtype virtualmachine SearchRoot-$_.moref-filtre @{"Config.Template"="False"}).} County}}, @{N = 'Templates'; E = {$clname = $_.name;} ($clusters |?) {$_. Name - eq $clname}). County}}

    First to initialize the $clusters and then run the second command.

    $clusters will get the cluster name and the number of models registered in these groups

    Once it's done

    By running the second command you will iterate thourhg ALL clusters (because when $clusters is initialized only be gets clusters where it can find templates, so you can have some clusters that were not included because they were not all in there)

    While it is an iteration thourhg all clusters. He puts a column called VM, which is the number of all the vms(without templates) who reside within this cluster, then the extra column based on variable $clusters, where he seeks the same cluster and then name it gets the count property.

    In the end, you should see something like this:

    Name                                                                                                          VMs Templates
    ----                                                                                                          --- ---------
    cluster=1                                                                                                         3
    Cluster-2                                                                                                         4      2
    cluster-3                                                                                                         1       6

    Kind regards

    Greg

  • marking of documents created in the last week with the word 'NEW '.

    Hi all.

    I have a mysql database with a table 'articles' containing the following (and other) fields:

    • category_name
    • Date_Created
    • level_name
    • title
    • Summary

    I have set up a query to extract information on the statutes of the db. The questioning of basic works very well. It looks like this:

    $r = @mysqli_query ($dbc, $q);

    / * display the results * /.

    If ($r) {}

    while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {}

    echo "< div class ="derniers_articles"> < strong class >: < facilities >". "." $row ["category_name"]. ' < br / > < strong > < em > posted on: < facilities > '. $row ["date_created"]. ' < br / > < level >: < facilities > '. $row ["level_name"]. "< /em > < h3 > '. $row ["title"]. "< / h3 > < class p ="last_ten"> < em >. $row ["Summary"]. ' < /em > < /p > < / div > ';

    }

    mysqli_free_result ($r);

    } else {}

    echo "< p > Prob get the info you need." < /p > ';

    }

    The query gives me result like this:

    Category: News
    Posted the: 2011-02-10 22:58:05
    Level: 5, 6

    Are you interested in politics?

    There are too many young people who don't is interested not in politics. It's a secret United Nations pay no one. However, this isn't the case of Darcy Lonergan who, at 21 years old, the youngest is launching itself candidates who pour win a seat in the next Parliament.

    Now, I want to mark all records created in the last week with the word 'NEW' so I inserted the line in bold in the following code:

    $r = @mysqli_query ($dbc, $q);

    / * display the results * /.

    If ($r) {}

    While ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {}

    echo "< div class ="derniers_articles"> < strong class >: < facilities >". "." $row ["category_name"];

    If (DATE_SUB (CURDATE (), 7 DAYS INTERVAL < = DATE($row['date_created']))) echo "< strong > NEW < facilities > ';"

    echo "< br / > < strong > < em > posted on: < facilities > '." $row ["date_created"]. ' < br / > < level >: < facilities > '. $row ["level_name"]. "< /em > < h3 > '. $row ["title"]. "< / h3 > < class p ="last_ten"> < em >. $row ["Summary"]. ' < /em > < /p > < / div > ';

    }

    mysqli_free_result ($r);

    } else {}

    echo "< p > Prob get the info you need." < /p > ';

    }

    .. but he throws this error:

    Parse error: syntax error, unexpected T_LNUMBER in [file path] on line 31

    31 is the "BOLD" line, I inserted. Can someone tell me what I am doing wrong? ("The date_created field is a timestamp like this ' 2011-01-08 18:06:39 '.)

    I'm new to php so be nice!...

    Thanks in advance.

    Hugh

    I think I'd be inclined to do in the query.

    By example SELECT field1, Field2, field3, etc, IF (DATEDIFF (NOW (), dtCreated)< 7,="" 'new',="" '')="" as="" recordstatus="" from="">

    Then echo just the value of the recordStatus for each record.

  • Details of the line of summary data creation

    Hi all

    I have a summary table that I use to try to create a table on the detail row. I use Oracle 10 g, and the table looks like this:

    STORE ZIP JAN4_2008 JAN11_2008 JAN18_2008 JAN25_2008... AUG29_2008
    1 72756 5 6 10 0 30
    2 30529 0 8 3 0 11
    3 74464 8 9 0 2 2
    .
    .
    .
    2550 72113 3 8 5 0 0

    There are a total of 2 550 stores and 40 weeks. However, I was invited to change the format of the table, so everything is the detail of the line, as follows:

    STORE ZIP DATE UNITS
    1 72756 JAN4_2008 5
    1 72756 JAN11_2008 6
    1 72756 JAN18_2008 10
    72756 1 JAN25_2008 0
    1 72756 AUG29_2008 30
    2 30529 JAN4_2008 0
    30529 2 JAN11_2008 8
    30529 2 JAN18_2008 3
    2 30529 JAN25_2008 0
    2 30529 AUG29_2008 11
    .
    .
    .
    2550 72113 JAN4_2008 3
    2550 72113 JAN11_2008 8
    2550 72113 JAN18_2008 5
    2550 72113 JAN25_2008 0
    2550 72113 AUG29_2008 0

    I'm sorry for what it looks like, but he pulled out the tabs and spaces when I posted. So my question is what instructions SQL do I need to create the new table, or what code should I? I tried to figure out how to do this in Oracle, but I think it's beyond my knowledge. I know SQL and use it almost every day, but I'm not a programmer. If something like this has been asked and answered before, I apologize. I didn't know how to find something like that.
    Thanks for your help.

    Hi skols.

    You need something like this:

    create table stores (store_id number(10) not null
                        ,zip number(5) not null
                        ,constraint stores_pk primary key (store_id)); 
    
    create table unpivot(store_id number(10) not null
                        ,store_date date not null
                        ,units number(10) not null
                        ,constraint unpivot_pk
                            primary key (store_id, store_date)
                        ,constraint unpivot_stores_fk
                            foreign key (store_id) references stores (store_id)); 
    
    insert into stores select distinct store, zip from pivot; 
    
    insert into unpivot (store_id, store_date, units)
    select store, to_date('JAN-04-2008', 'MON-DD-YYYY'), jan4_2008 from pivot
    union all
    select store, to_date('JAN-11-2008', 'MON-DD-YYYY'), jan11_2008 from pivot
    union all
    ....;
    

    Concerning
    Peter

  • I've recently migrated my iPhotos to Photos, perfectly worked for a few weeks, but suddenly today, I can't open my photos in pictures

    I recently migrated from iPhoto to Photos worked perfectly and I used it for a few weeks, but today I can open my pictures suddenly not in pictures. What's wrong?

    No idea since we can't see you - you must provide details - why you can't open pictures? What is going on? What is you get the exact error message? What version of the operating system and Photos you have?

    and there's a photo for Mac forum, which is where you can ask questions Photos - I will ask to be moved your message

    LN

  • Numbers: trying to AutoFill for all dates the three weeks

    Numbers: You're Auto Fill dates for all three weeks?   Unable to do so... any suggestions... Thank you...

    Here's my proposal on what you ask for:

    Make sure that the table has 22 ranks as indicated.

    Enter the start date in cell E1

    A2 = 1 + INT ((ROW () −2) ÷7)

    It's shorthand dethrone select cell A2, and then type (or copy and paste it here) the formula:

    = 1 + INT ((ROW () −2) ÷7)

    B2 = MOD (ROW () −2, 7) + 1

    C2 = E1 + (−2) LINE

    Select cells A2 through C2, copy

    Select cells A2 at the end of the C column, paste

  • I called Amazon to try to recover the serial number of my old iPod classic two weeks ago, and they gave me a kind of account; They pronounce it account 'seen - It '.

    I called Amazon to try to recover the serial number of my old iPod classic two weeks ago, and they gave me a kind of account; They pronounce it account 'seen - It '. I don't have to ask how, because I thought I knew, but I was wrong. Would what type of account be? And how it's spelled? The name of the account is a tiny s followed a 7-digit number. (Of course I will not type the numbers.)

    I would go to a forum for Amazon, because they can be better equipped to answer a question on their system. If synchronize you the device with iTunes, the number can be there in the backup section.  Find the serial number of your Apple - Apple Support product

  • Week old iPhone 7 displays "sim" invalid error

    Week old 7 128 GB iPhone displays "invalid sim" error intermittently. Nothing in particular seems to make. Just shows up randomly. If I turned off and restart it solves for a while. I'm getting a couple of times a day now. Anyone else having this problem? How should I do? I intend to go back to the Apple Store where I had tomorrow.

    This page can help you

    If you receive an alert on the SIM card in your iPhone - Apple Support

  • I got 'Triple 7 slots' for more than 2 years, with a bit of money on it, last week that it had to be updated, it would not update, so I removed it, the downloaded it again once, now my money is gone...

    I had "Extreme Triple Shots" on my MacBook Pro for over 2 years... He had to be updated, and then he never recovered last week, yesterday he disappeared from my Mac, so I downloaded again, now I don't have any money there, which was very little... What can I do to get my money back on...

    Ppenny

    < personal information deleted by host >

    Contact the developer of the app. This is not an Apple product.

  • Apple Watch sport does not work correctly. The display is 'crazy' once or twice a week and I need to force restart it. Do you know what is happening with the watch? Is this a common failure?

    Apple Watch isn't working properly. The display is to be 'crazy' once or twice a week. And I need to force restart it. Is this a common failure?

    Hello

    This isn't a failure or defect.

    Zoom (an accessibility function) has been activated on your watch and you are zoomed accidentally tapping on the screen in a particular way.

    • To turn off the Zoom:
      • On your iPhone, in the application of the watch, go to: My Watch (tab) > general > accessibility > Zoom - put it off.
      • Or on your watch, go to: homescreen (via a simple press on the digital Crown) > (cog icon) settings > general > accessibility > Zoom - tap and enable / disable.
    • If the accessibility shortcut has been enabled and configured for the Zoom, you can also enable and disable functionality more conveniently:
      • On your watch: quickly press the digital Crown (the round button) three times.
    • To set up accessibility shortcuts:
      • On your iPhone, in the application of the watch, go to: Watch My > general > accessibility > accessibility shortcut (bottom) > select / deselect Zoom.

Maybe you are looking for

  • Skype is not responding

    Skype stopped responding whenever I try to call someone, or to join a group call. This problem has occurred while I was in a call with a friend, and it has just stopped responding out of nowhere. It also crashed when I tried to change my camera setti

  • Sony Vaio E series applications Netflix and hulu does not work

    I have download the Netflix app and hulu, because I had these accounts for nearly a year already and I tried to stream movies on these applications and it does not play. Sony technicians can not fix it either. Does anyone have the same problem with t

  • Wireless R50E

    This may seem a bit noob but I'm new to computer laptop r50e (got free, love!) I read that r50e had wireless lan, but I can't find one in my book, he got the fn + computer button that starts the wifi, it also got bios information to not turn the netw

  • BlackBerry Smartphones to check an e-mail

    I had to move from a 9810 to a 7820 but keeping the same id, e-mail addresses etc. I get e-mails to the 7820, and I can see who they are and the header of the object. I can't see the body of the e-mail message. Can anyone help? Thanks, Stu

  • Impression on the LPT ports on Server 2008

    Hi all I use an application via RDP on a Server 2008 R2 server. The application prints directly to a pre-defined LPT port, on the same server, which is redirected. When I print it does not say that it cannot find the port. I tried running the applica