How can we make the Partition on the result using only sql?

Hello

How to make the partition on sql result using the query.

sample
BPREF_NO     BILL_MONTt AVG_IND     partition
Q12345     1/31/2009     2     part1
Q12345     2/28/2009     2     part1
Q12345     3/31/2009     2     part1
Q12345     4/30/2009     2     part1
Q12345     5/31/2009     2     part1
Q12345     6/30/2009     1     part1
Q12345     7/31/2009     2     part1
Q12345     9/30/2009     1     part2
Q12345     10/31/2009     2     part2
Q12345     11/30/2009     2     part2
Q12345     1/31/2010     1     part3
Q12345     2/28/2010     2     part3
Q12345     3/31/2010     2     part3
Q12345     11/30/2011     2     part4
Q12345     2/29/2012     2     part5
Q12345     3/31/2012     2     part5
Q12345     4/30/2012     2     part5
Q12345     5/31/2012     2     part5
Q12345     7/31/2012     2     part6
I want to create the partition column using the query
from the logic below

If bill_month is the sequence then it must create a partition and if the breaks we need to introduce the new partition.

just for example...
January 31, 2009 to July 31, 2009 is called part1
August 30, 2009 to November 30, 2009 called part2
like wise...

is it possible to make the partition of the query itself.

Please guide me in this regard

Thanks in advance

Iqbal
with testdata as (
select 'Q12345' BPREF_NO, to_date('1/31/2009','MM/DD/YYYY') BILL_MONTt,2 AVG_IND from dual union all
select 'Q12345', to_date('2/28/2009','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('3/31/2009','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('4/30/2009','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('5/31/2009','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('6/30/2009','MM/DD/YYYY'),1 from dual union all
select 'Q12345', to_date('7/31/2009','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('9/30/2009','MM/DD/YYYY'),1 from dual union all
select 'Q12345', to_date('10/31/2009','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('11/30/2009','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('1/31/2010','MM/DD/YYYY'),1 from dual union all
select 'Q12345', to_date('2/28/2010','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('3/31/2010','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('11/30/2011','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('2/29/2012','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('3/31/2012','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('4/30/2012','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('5/31/2012','MM/DD/YYYY'),2 from dual union all
select 'Q12345', to_date('7/31/2012','MM/DD/YYYY'),2 from dual
)

select
  BPREF_NO
, AVG_IND
, BILL_MONTt
, 'part'||
  sum (partition) over (partition by BPREF_NO order by BILL_MONTt)
  partition
from (
select
  BPREF_NO
, AVG_IND
, BILL_MONTt
, case
  when months_between (BILL_MONTt, lag(BILL_MONTt) over (partition by BPREF_NO order by BILL_MONTt)) = 1 then
  0 else 1 end partition
from testdata
)

BPREF_NO AVG_IND BILL_MONTT PARTITION
Q12345 2 01/31/2009 part1
Q12345 2 02/28/2009 part1
Q12345 2 03/31/2009 part1
Q12345 2 04/30/2009 part1
Q12345 2 05/31/2009 part1
Q12345 1 06/30/2009 part1
Q12345 2 07/31/2009 part1
Q12345 1 09/30/2009 part2
Q12345 2 10/31/2009 part2
Q12345 2 11/30/2009 part2
Q12345 1 01/31/2010 part3
Q12345 2 02/28/2010 part3
Q12345 2 03/31/2010 part3
Q12345 2 11/30/2011 part4
Q12345 2 02/29/2012 part5
Q12345 2 03/31/2012 part5
Q12345 2 04/30/2012 part5
Q12345 2 05/31/2012 part5
Q12345 2 07/31/2012 part6 

Tags: Database

Similar Questions

  • How can I make the best use of a new external hard drive and a new catalog full of photos just loaded into Photoshop elements 14 Organizer?

    How can I make the best use of a new external hard drive and a new catalog full of photos just loaded into Photoshop elements 14 Organizer?

    Keep all the files on external hard drive image?  Nothing else and no pictures on the desktop?

    Keep all image files both places?

    What is the best way to go through thousands of images in the Organizer to identify and place them in files?

    Once I've placed a file, I just leave it in the entire catalog or a way indicate to me that it has been sorted?

    As overwhelming, any tips/shortcuts/schemes, you can offer are welcome!

    As I only have the version of the EP, here is some info on the organiser:

    https://helpx.Adobe.com/Photoshop-elements/how-to/use-elements-Organizer.html

    Independent of how this feature works, you want to have your photos in one place and have a backup (second copy) somewhere else. All hard drives will not be successful at some point - some more early, some late - never trust to have your files in any safety devices if they are on a single disc. Once you have your sorted, it would be useful that you will organize/name/tag new photos immediately if the task is relatively short and simple. I copy my photos on my internal hard drive for my camera, take a quick look with preview to see who needs some changes and then decide where to put them - either drop them immediately after naming them or bring in an editing application and then file them away.

  • How can I make the matrix using numbers

    Yes, for now I'll try to find out how to use the numbers to do the multiplication of matrices

    Something like that?

    In cell A1, filled to the right and downwards:

    = SUMPRODUCT (Matrix 1::1:1, TRANSPOSE (matrix 2::A)))

    SG

  • How can I make the biggest impression

    How can I make the biggest impression on all Web sites? where is the setting? Thank you!

    To temporarily make more big, click on 'view' in the menu, then choose 'Zoom' & then it will allow you to set the zoom to larger or smaller.

    If you want to definitely bigger, if you have a Mac, click on 'Firefox', then 'Préférences' / If you have Windoze choose 'Tools', then 'Options' (both look the same from here...), then click the "Content" icon and change the font size.

    That should do it...

  • On another PC I want to save my favorites, but my browser Firefox does not work how can I make the backup, before I reinstall Firefox

    On another PC I want to save my favorites, but my browser Firefox does not work how can I make the backup, before I reinstall Firefox.
    Firefox cannot renew its tabs and now won't run and let me do a backup

    This may be considered to be solve my problem.
    I decided to uninstall the rogue program Firefox download and reinstall the same version (No. 8). I used Windows XP Add Remove programs who asked if I wanted to save the settings of Firefox until I uninstalled Firefox. I said yes and operated with the uninstall. I couldn't find a Firefox 8 so I went for the 12 version and installed on the laptop. This version 12 now works with all the passwords one favorite of the uninstalled 8.
    Thank you for all your help and advice.

  • Re: Satellite A300 - how can I make the webcam work on Win7

    Hello everyone.

    I had Win Vista installed on this Satellite A300 and it worked well.
    I had no problem at all.

    Then I moved to Win7 and now I'm going through the test of the work of webcam.
    I tried to install all types of drivers, even those for A500, but it would be of no use.

    So, how can I make the webcam work on my A300?

    I've tried everything, even the installation of Ubuntu on this laptop and still it wouldn't work. If this is your interest, I'm under Win7 in Spanish, x 32, Home Edition.

    I really need your help here, please, I beg you, I spent 5 days ago almost try ANYTHING!
    And yet, I get the message after each installation/reboot of the: "the camara web esta disabled o ha Fall.» "Por favor, it check las web camara su configs", which would result in something like "the webcam is disabled or it has failed. Please check the configuration of your webcam. I've been browsing the forum for related issues, but I have not found any solution :(

    Thanks in advance,

    Ozma.

    Hello

    Seems the webcam software has not been installed correctly.
    That Win 7 OS do you use? 32-bit or 64-bit?

    Here you can find Chicony webcam driver for Win 7 64 bit
    http://Support1.toshiba-tro.de/Tedd-files2/0/webcam-20091026100013.zip

    and here you can find Chicony webcam driver for Win 7 32 bit
    http://Support1.toshiba-tro.de/Tedd-files2/0/webcam-20091023184836.zip

    Good luck

  • When I get e-mails, printing is so so small I can barely read. How can I make the biggest impression

    When I open my emails to read, printing is so tiny that I can hardly read them. How can I make the biggest impression?

    Hello
    Try to view/Zoom/full Zoom In (ctrl + +).

  • How can I make the screen keyboard on disappear?

    How can I make the screen keyboard on disappear?

    Press the key at the bottom far right (icon with an arrow to the bottom of the keyboard).

  • My 6s iphone shows that I have an email unread in my Inbox.  I have read and open any emails in my Inbox, but my phone shows an unread email.  How can I make the 1 red go?

    My 6s iphone shows that I have an unread email.  I have read and open any emails in my Inbox.  How can I make the 1 red go?

    Go to settings > Mail, Contacts, calendars > press e-mail account. Put the Mail DISABLE (display white side). To return to the home screen (it's essential!). Phone power off. Turn the phone to power back on. Mail switch must stay off - if enabled, you will need to repeat this process. If it is disabled, you did it right - turn it on and the 'ghost' post should have gone - for now. That they will probably come back until this bug is fixed permanently.

  • How can I make the computer asks for a password before downloading a program?

    How can I make the computer asks for a password before downloading a program?

    Hello

    You can configure the computer to request the password when you install any program using the User Account Control (UAC) on the computer. But you will not be able to make windows to ask password when you try to download and program.

    You can check the link next on change control settings of user account for more information.

    http://Windows.Microsoft.com/en-us/Windows-Vista/your-permission-please-understanding-user-account-control-in-Windows-Vista

    http://Windows.Microsoft.com/en-us/Windows-Vista/how-do-I-change-the-behavior-of-the-user-account-control-message

    You can use any program of third-party download manager in which you can set a password when you download any file/program on the computer. You can use your favorite search engine to find any Download Manager for the browser software.

    Warning: Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

  • How can I make the computer sleep after 5 minutes of inactivity on the logon screen?

    Original title: How to sleep in the login screen?

    How can I make the computer sleep after 5 minutes of inactivity on the logon screen? Currently, on the login screen, white screen, but the computer is still running. Sleeping would save a lot of energy because the computer is used most of the time.

    Hi Phil.Ganchev,
     
    Using a laptop or a desktop computer?
     
    The reason for this question is, if you have a plugged AC adapter you must set power accordingly as opposed to laptop settings battery operated.
     
    I suggest you head over to the power settings and create your own power management.
     
    a. power by clicking on the Start button, open the Options click on the Control Panel, clicking system and security, and then clicking Power Options.

    (b) according to the plan you want to change, click on change plan settings.

    c. on the parameters of change in the plan page, choose "Put the computer to sleep" that you want to use when your computer is running on battery (if applicable) and when it is plugged.
    (Change in 5 minutes for the batteries and sector)
     
    Reference:
     
    Power plans: frequently asked questions

    Aziz Nadeem - Microsoft Support

    [If this post was helpful, please click the button "Vote as helpful" (green triangle). If it can help solve your problem, click on the button 'Propose as answer' or 'mark as answer '. [By proposing / marking a post as answer or useful you help others find the answer more quickly.]

  • How can I make the tΓches play a mp3 file at some point please?

    I would like to that task scheduler to open windows media player and play an MP3 for me at a given time. I followed the instructions here, but nothing helps. The windows media player window does not open, but it does not play mp3.

    http://www.Vistax64.com/tutorials/132903-Task-Scheduler-create-task.html

    In the program/script box, I put in "C:\Program Files\Windows Media Player\wmplayer.exe '.

    In the Add arguments box, I put in: Wildlife.mp3

    At the beginning of area (optional), I put in: C:\Reminders

    which is a folder that I created in the C drive.

    Wildlife.MP3 file is of course in the C\Reminders folder.

    I have Windows 7.

    How can I make the tΓches play a mp3 file at some point please?

    In the arguments to the full path of the file in quotes, "c:\reminders\wildlife.mp3."

    http://Windows.Microsoft.com/en-us/Windows7/schedule-a-task

  • How can I make the header fixed while scrolling?

    forget that, how can I make the header while scrolling fixed?
    until this that no point visible in the header, it disappears as well.

    [title amended to reflect content]

    Please keep to one question per thread.

    You can assign the sticky HeaderMode...

    http://developer.BlackBerry.com/native/reference/Cascades/bb__cascades__stacklistlayout.html#propert...

    http://developer.BlackBerry.com/native/reference/Cascades/bb__cascades__listheadermode.html#enum-Typ...

  • How can I make the start menu bigger?

    How can I make the start menu bigger? GO BROWNS!

    What do you mean largest? More Articles?

    If so, right click on the ORB start and select Properties.

    Click Customize, and then down, to increase the number of programs to display.

  • have 5 LR and CC. The folders are different, some are missing in the CC. And some complete are not available in CC. I'm looking forward to use CC rather than LR5 so how can I make the folders and collections even on each?

    have 5 LR and CC. The folders are different, some are missing in the CC. And some Collections are not available in CC. I'm looking forward to use CC rather than LR5 so how can I make the folders and collections even on each?

    Hi cjohnm,

    You can use the 5 Lightroom Catalog and improve it in Lightroom 6, therefor all folders and collections will be identical in both version.

    Open the Lightroom all holding the key Alt/Opt and select only the 5 Lightroom Catalog and it will switch to it.

    Let us know if that helps.

    Kind regards

    Mohit

Maybe you are looking for

  • How can I configure the order of networks wifi on my iPhone 6?

    I was browsing the Internet and looking for throughout my general settings but I'm not able to find a way to configure the order of networks wifi on my phone, as I can with my MacBook Air (via Network Preferences > advanced > tab Wi - fi). I had to d

  • Number key pad vs QWERTY?

    I am trying to add a shortcut through the side number of my keyboard (which is a LogicKeyboard - for AppleLogic) you can see here 'record' a small icon noting it is 3 through the keypad.  but when I announced "1 and 2" for Protools style FFF and RR t

  • Qosmio X 300 - GPU overheating

    Hey guys So I bought my X 300 in 2009, since then it has been excluded to replace the GPU and the card mother SEPARATED THREE TIMES.Once again the weekend over heated and now I cannot use it! I have the Toshiba drivers installed, not those of nvidia

  • Update Firmware on printer C410

    Printer is on wireless and works very well for all applications.  Tried to activate ePrint and it displays the message "there was a problem connecting to the server."  Also tried to download updates to the printer and received the same message.  Any

  • Playlists and shuffle

    Droid Razr My playlist of music via BLUETOOTH to my 2010Tundra synchronizations. Whenever I have quit and return lists of reading starts from the first song ever played. How can I get the shuffle to take over.