How to add extra per day records based on maximum occurances in the week.
Hello,
I need to add extra records based on maximum occurances on a day in a week.
For example, the result of the query shows that maximum occuances in a week 0 is 3 on so I need to add empty records in each day in that week.
SQL QUERY:
with numbers as (
SELECT ROWNUM N FROM dual
CONNECT BY LEVEL <=35
),months as (
SELECT ADD_MONTHS('01-JUN-10',n-1) AS current_month,
TO_CHAR(ADD_MONTHS('01-JUN-10',n-1),'fmMonth-YYYY') AS current_month_label
FROM numbers
WHERE ADD_MONTHS('01-JUN-10',n-1) <= NVL(add_months('01-JUN-10', :monthcount-1),:p_month)
ORDER BY n ASC
) , dates as (
select trunc(trunc(m.current_month, 'MM'), 'D') + n - 1 calendar_date,
trunc((n - 1) / 7) AS week_num,
m.current_month as current_month
from numbers, months m
where trunc(dom.schedule.calendar_begin(m.current_month) + n - 1, 'd') <= last_day(m.current_month)
Order By week_num, calendar_date
select dates.week_num, edate, name from (
--week 0
select '30-MAY-10' as edate, 'JJ' as name from dual union
select '31-MAY-10' as edate, 'MK' as name from dual union
select '01-JUN-10' as edate, 'MK' as name from dual union
select '01-JUN-10' as edate, 'BK' as name from dual union
select '01-JUN-10' as edate, 'JJ' as name from dual union
select '04-JUN-10' as edate, 'KK' as name from dual union
select '04-JUN-10' as edate, 'LA' as name from dual union
-- week 1
select '06-JUN-10' as edate, 'BK' as name from dual union
select '06-JUN-10' as edate, 'JJ' as name from dual union
select '07-JUN-10' as edate, 'KK' as name from dual union
select '11-JUN-10' as edate, 'LA' as name from dual
) a join dates on dates.calendar_date = a.edate
order by week_num, to_date(edate);CURRENT RESULT :
WEEK_NUM EDATE NAME
0 30-MAY-10 JJ
0 31-MAY-10 MK
0 01-JUN-10 MK
0 01-JUN-10 JJ
0 01-JUN-10 BK
0 04-JUN-10 KK
0 04-JUN-10 LA
1 06-JUN-10 BK
1 06-JUN-10 JJ
1 07-JUN-10 KK
1 11-JUN-10 LAREQUIRED RESULT:
WEEK_NUM EDATE NAME
0 30-MAY-10 JJ
0 30-MAY-10 null
0 30-MAY-10 null
0 31-MAY-10 MK
0 31-MAY-10 null
0 31-MAY-10 null
0 01-JUN-10 BK
0 01-JUN-10 JJ
0 01-JUN-10 MK
0 02-JUN-10 null
0 02-JUN-10 null
0 02-JUN-10 null
0 03-JUN-10 null
0 03-JUN-10 null
0 03-JUN-10 null
0 04-JUN-10 KK
0 04-JUN-10 LA
0 04-JUN-10 null
0 05-JUN-10 null
0 05-JUN-10 null
0 05-JUN-10 null
--Number of Week 1 records should be 14 = (max occurances on 06-JUN-10) * 7
1 06-JUN-10 BK
1 06-JUN-10 JJ
1 07-JUN-10 KK
1 07-JUN-10 null
1 08-JUN-10 null
1 08-JUN-10 null
1 09-JUN-10 null
1 09-JUN-10 null
1 10-JUN-10 null
1 10-JUN-10 null
1 11-JUN-10 LA
1 11-JUN-10 null
1 12-JUN-10 null
1 12-JUN-10 nullI would appreciate it if you could help me to find efficient way to achieve this?
Thanks,
GM
Edited by: user12068331 on Sep 28, 2010 2:17 PM
Edited by: user12068331 on Sep 28, 2010 2:48 PM
Ok,
Few things to clarify first :
1 - How do you define week number ?
Oracle has 2 different way for week number : normal week number (WW) and isoweek (IW).
is your weeknumber one of those, or is it something else ?
2 - Depending on the country the week doesn't start on the same day : in France (as most of Europe I think) first day is monday, where in the USA (as far as I know) first day is sunday.
the to_char builtin function can display weeknumber :with a as (
--week 0
select 0 as weeknum, to_date('30-MAY-2010','DD-MON-YYYY') as edate, 'JJ' as name from dual union all
select 0 as weeknum, to_date('31-MAY-2010','DD-MON-YYYY') as edate, 'MK' as name from dual union all
select 0 as weeknum, to_date('01-JUN-2010','DD-MON-YYYY') as edate, 'MK' as name from dual union all
select 0 as weeknum, to_date('01-JUN-2010','DD-MON-YYYY') as edate, 'BK' as name from dual union all
select 0 as weeknum, to_date('01-JUN-2010','DD-MON-YYYY') as edate, 'JJ' as name from dual union all
select 0 as weeknum, to_date('04-JUN-2010','DD-MON-YYYY') as edate, 'KK' as name from dual union all
select 0 as weeknum, to_date('04-JUN-2010','DD-MON-YYYY') as edate, 'LA' as name from dual union all
-- week 1
select 1 as weeknum, to_date('06-JUN-2010','DD-MON-YYYY') as edate, 'BK' as name from dual union all
select 1 as weeknum, to_date('06-JUN-2010','DD-MON-YYYY') as edate, 'JJ' as name from dual union all
select 1 as weeknum, to_date('07-JUN-2010','DD-MON-YYYY') as edate, 'KK' as name from dual union all
select 1 as weeknum, to_date('11-JUN-2010','DD-MON-YYYY') as edate, 'LA' as name from dual
select to_char(a.edate,'IW') isoweek, to_char(a.edate,'WW') numweek, a.*
from a;
IS NU WEEKNUM EDATE NA
21 22 0 Sunday 30/05/2010 00:00:00 JJ
22 22 0 Monday 31/05/2010 00:00:00 MK
22 22 0 Tuesday 01/06/2010 00:00:00 MK
22 22 0 Tuesday 01/06/2010 00:00:00 BK
22 22 0 Tuesday 01/06/2010 00:00:00 JJ
22 23 0 Friday 04/06/2010 00:00:00 KK
22 23 0 Friday 04/06/2010 00:00:00 LA
22 23 1 Sunday 06/06/2010 00:00:00 BK
22 23 1 Sunday 06/06/2010 00:00:00 JJ
23 23 1 Monday 07/06/2010 00:00:00 KK
23 24 1 Friday 11/06/2010 00:00:00 LA
11 rows selected.
Similar Messages
-
I am working on a chart in pages with 7 columns.
Problem has occurred with amount of rows. I have completed 999 rows and it won't allow me to continue. As I need to do approx 3000+ rows, can anyone explain to me how to add extra rows. Thanks JaneTry posting in the Pages forum
https://discussions.apple.com/community/iwork/pages -
How to add extra options for style of images in pages. iPad version has far more options than Mac version
Thank you, you made me go look again and I realised the ones I use on the iPad are under Borders not style and they are on Mac also. I feel a bit silly but I wouldn't have got there without your prompting. Do you mean by "create your own" using the borders and then saving as a style or can you create something that is not in either?
Thanks again -
How to add extra labels into Bridge CS5?
Hi folks, nice to meet you all.
I do not want to edit or rename the existing 5 existing labels into Bridge CS5. I just want to create new labels. So, I want to add extra labels to have more than 5 labels.
Does anybody know how to add extra labels into Bridge CS5? If so, please, tell me how to do it.
Thanks.You should move this post to the new Bridge forum as this one will soon die. Here is link http://forums.adobe.com/community/bridge/general
-
How to add extra tab in bapi at item level
hi developer,
please guide me in solving this problem i.e how to add extra tab in bapi at item level .
thanks .
raviWhat are you exactly asking for, I don't understand your question...
Transaction screen, adding a tab / customer fields
Business Object / BAPI, modifying BAPI signature, extension
NB : The quality of an answer depends significantly on the quality of the question ...
Regards,
Raymond -
I am unable to find instructions on how to add a bookmark. I don't want it on the toolbar
I am unable to find instructions on how to add a bookmark. I don't want it on the toolbar but just in the list of bookmarks. I've tried every which way to search for this information but without success.
Thanks,
D Lapp
Email: <[email protected]>
I removed the email address. It is not needed on the forum to send you replies. The forum is public and indexed by search engines. You may reinstate the email address if you wish. You may also choose to display the email address publicly in your profile use [/users/edit] ->''Make my email public: ''[] ~J99If you want to bookmark the current page, you can use the keyboard shortcut Ctrl+d to add the bookmark.
If you prefer to type the address, or you need to bookmark a page that is not displayed, right-click an existing bookmark on the Bookmarks menu (or in the folder where you want to add the bookmark) and choose New Bookmark.
Is that what you're looking for? -
How to add extra blank space in xml
I open the xml file in notepad I get this
<XXON_EXT_BANK_ACCOUNT_NAME>創名聯合會計師事務所 </XXON_EXT_BANK_ACCOUNT_NAME>
But when I open the xml file in html format the blank space is gone.
How can I add extra blank space in xml?Hi
Why do you need the extra space for?
This difference in display that you see between your browser and notepad/notepad++
will not affect your generated report.
Bogdan -
How to backup ONCE per DAY only
Hi
It takes forever (2hrs+) to backup 300GB onto our Time Capsule, and the backup slows down my computer so much to the point I want to pull my hair out! I can't seem to find a way to do an automatic backup once per day only rather than hourly without turning off the automatic backup and doing it manually.
Does anyone know how to do an automatic backup to Time Capsule once per day only?
Thank you!Thank you for your assistance!
That is exactly what I was looking for, and am very relieved to know there is something available!!
I was hesitant to download it at first because since it is backing up all my files, I was afraid of the possibility of having a built in bug that would allow an outsider to access my files. However, I researched it, and it seems there are many happy & satisfied users of the Time Machine Editor software.
Thanks again! Hopefully Apple will just swallow their pride and make this ability available in one of their own software updates in the future. -
How to add sound effects to recorded sound?
HI there
I am making an app which will record ur voice and then add sound effects to it. How can i add those sound effects such as a higher pitchHi AhmadTheXboy,
Actually this forum is to discuss the VS IDE usage, this issue would be related to the specific language development.
Feng Chen shared us some samples here:
How
do I capture sound?
The following threads is about the similar issue, they use the VB language in winform apps.
How
to add music and sound effects to a Windows Form Application?
how
to create sound recorder
Hope they could provide useful information for you.
If still no help, please select the correct language development forum here:
http://social.msdn.microsoft.com/Forums/en-US/home?category=vslanguages&filter=alltypes&sort=lastpostdesc
Sincerely,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a
href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey. -
How to add extra lines in the address field?
How, if possible, to add extra lines in the address field? For example, the street address might require two lines:
Bob Smith
Newport A Unit 32
Century Village
Aventura, FLThanks, Barney! It's even easier than the solution I came to: copying and pasting into the field.
-
Hi all...
I'm doing a system for a hospital, and I need to count the number of patients taken care of per day by some sector of the hospital.
In the mysql database i have the day that the patient interned and the they he left the hospital...
how can I do that???
thx...Hi all...
I'm doing a system for a hospital, and I need to
count the number of patients taken care of per day
by some sector of the hospital.
In the mysql database i have the day that the patient
interned and the they he left the hospital...
how can I do that???
thx...Do you have a specific Java question? If so, please post it here. -
How to add extra field in cube
hi guys,
iam learner of bw.
iam extracting the data from r/3 to bw.
for example sales cube(0sd_c05).
i want to add one more field in r/3 side according to client req for ex.in 2lis_11_vahdr.
how to add that extra field in 0sd_c05.
kindly give me steps one by one for my understanding.
i will appreciate and giving points .
thankuKumar
To do that first you have to enhance the Datasource 2lis_11_vahdr in R/3 side with new fields and populate these fields with data using user exit. As a next step as this field in to your Cube
Please see these links for enhancements
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/59069d90-0201-0010-fd81-d5e11994d8b5
Re: enhancements
Hope this helps
Thnaks
Sat -
How to Add extra link at top My dashboard OBIEE page.
Hi folks,
I have a requirement wherein I need to add extra link besides the Answer, dashboards link in the OBIEE my dashboard page. Could you please let me know how to achieve it.
ThanksHi,
I think the above customization is kind of normal customization. I am looking add up new link besides Dashboard - Answers - Administration - My Account Tabs and make it functioning. How is it possible to make that happen?
Thanks:
Apurv. -
How to add extra column in query designer
Hello Guru's,
I got the query like this
Actuals
cal/month 01/2008 02/2008 03/2008
cash
reveunve
liabilities
i need the query to be like this
Actuals
cal/ months 01/2008 02/2008 03/2008 Q1 04/2008 05/2008 06 2008 Q2
cash
revenue
libilities
that Q1 is sum of first three months,
can you please tell me how to add extracolumn and add those.
Thanks,
snehaHi sneha,
You can do this by using structure .Create the selection for3 month using variable and defining offset for that, creat new formula for Q1 = 123 , then create same selection for next 3 months and same for Q2.
Regards,
Sumit. -
How many iPhones stolen per day? Prevent shutdown.
Dear friends.
Since I had my iPhone stolen I'm searching for a way (without jailbreaking it) to prevent that my new iPhone gets lost.
"Find my iPhone" is only useful when the thief is dum.b as hel.l and when nobody has found it (yet).
Does Apple see comercial advantages on this situation? How many iPhones are stolen a day?!
I mean, why in the world wouldn't you develop security apps and security features so we don't lose our beloved phones?
This is serious, and it seems Apple doesn't care. I don't want to jailbreak my iPhone, but you are not helping, Apple!
I would like to see a Restriction setting that would block the shutdown of my iPhone when it's locked. It would require a passcode to shut it down. It's so simple!
This way thieves wouldn't be able to shut it down!
The same works for Airplane mode and Wi-Fi. A passcode should be required to turn it off (if I enable this feature).
Advanced considerations: DFU mode and recovery mode should "expire", the iPhone should reset itself after some time (e.g. 10 minutes) so the iPhone would come back to life and allow tracking.
SECURITY!
So far nothing was done in this area. I believe Apple should pay more attention to this.
Best regards,
WillWill Segatto wrote:
Dear friends.
Since I had my iPhone stolen I'm searching for a way (without jailbreaking it) to prevent that my new iPhone gets lost.
"Find my iPhone" is only useful when the thief is dum.b as hel.l and when nobody has found it (yet).
Does Apple see comercial advantages on this situation? How many iPhones are stolen a day?!
I mean, why in the world wouldn't you develop security apps and security features so we don't lose our beloved phones?
This is serious, and it seems Apple doesn't care. I don't want to jailbreak my iPhone, but you are not helping, Apple!
I would like to see a Restriction setting that would block the shutdown of my iPhone when it's locked. It would require a passcode to shut it down. It's so simple!
This way thieves wouldn't be able to shut it down!
The same works for Airplane mode and Wi-Fi. A passcode should be required to turn it off (if I enable this feature).
Advanced considerations: DFU mode and recovery mode should "expire", the iPhone should reset itself after some time (e.g. 10 minutes) so the iPhone would come back to life and allow tracking.
SECURITY!
So far nothing was done in this area. I believe Apple should pay more attention to this.
Best regards,
Will
Sorry requiring a passcode to shut down the phone isn't a good idea.
do you know how many users forget their 4 digit passcode to unlock their phones - use the search function at the top right and you'll see all the threads.
Maybe you are looking for
-
Imported XML errors "java.io.UTFDataFormatException: Invalid UTF8 encoding"
Hi, I had to display a mutli select table region in a Oracle Standard Supplier Site Manage page in R12. So I had a created a custom Stack Layout region and imported in to the database. The import went through fine. Then using Personalization i had cr
-
CS4 Photoshop.exe file name changes
Has anyone had the CS4 Photoshop.exe file change names? I have had this happen on a couple of computers, one machine it happened twice. When CS4 is installed, the Photoshop file name is Photoshop.exe, at some point, the file name changes to PHOTOSHOP
-
JDeveloper and other Oracle JAR files with antivirus on access scanning
Hi concerns in our IT department about security means that the AV software scans jar files on our client PC's and servers. This means that JDeveloper starts very slowly, even on a 3.2GHz PC. Can anyone tell me how to get around this or at least which
-
hi...i wanna to ask, why all my method after setVisible() in a JDialog would not run?
-
Hi all, I am planning to install the cluster on our machines, can anyone please provide us the good documentation on how to install soa on a cluster environment and performance tuning document too. Currently we are running on standalone installation.