First occurrence but not in the same table

As we know, to search for the first occurrence of a particular record, we go with the MIN function. It is however, if all of your records are in the same table.

My scenario is a little different. I have 4 tables (maybe more), but keeping this is simple for the exercise. I need to find the first occurrence of a student who appear in a table and this registration Date. The trick is to NOT include this student in the following tables. To do this, I can use SQL or PL/SQL.

Thanks in advance.

Scripts for Tables (CREATE TABLE and INSERT scripts)

create table time_period(id varchar2(1), start_date date, end_date date);
insert into time_period values('0', to_date('01-DEC-2005', 'DD-MON-YYYY'), to_date('31-MAY-2006','DD-MON-YYYY'));
insert into time_period values('1', to_date('01-JUN-2006', 'DD-MON-YYYY'), to_date('30-NOV-2006','DD-MON-YYYY'));
insert into time_period values('2', to_date('01-DEC-2006', 'DD-MON-YYYY'), to_date('31-MAY-2007','DD-MON-YYYY'));
insert into time_period values('3', to_date('01-JUN-2007', 'DD-MON-YYYY'), to_date('30-NOV-2007','DD-MON-YYYY'));
insert into time_period values('4', to_date('01-DEC-2007', 'DD-MON-YYYY'), to_date('31-MAY-2008','DD-MON-YYYY'));

create table student_test1(student_id varchar2(4), exam_date date);
create table student_test2(student_id varchar2(4), exam_date date);
create table student_test3(student_id varchar2(4), exam_date date);
create table student_test4(student_id varchar2(4), exam_date date);

insert into student_test1 values('1001',to_date('01-DEC-2005','DD-MON-YYYY');
insert into student_test1 values('1002',to_date('01-DEC-2005','DD-MON-YYYY');
insert into student_test2 values('1003',to_date('01-JUN-2006','DD-MON-YYYY');
insert into student_test3 values('1001',to_date('01-NOV-2007','DD-MON-YYYY');
insert into student_test3 values('1004',to_date('01-NOV-2007','DD-MON-YYYY');
insert into student_test4 values('1001',to_date('01-MAY-2008','DD-MON-YYYY');
insert into student_test4 values('1002',to_date('01-MAY-2008','DD-MON-YYYY');
insert into student_test4 values('1003',to_date('01-MAY-2008','DD-MON-YYYY');
insert into student_test4 values('1004',to_date('01-MAY-2008','DD-MON-YYYY');

Desired output should be as follows:

ID Start Date End Date County

0 1 December 05 31 May 06 2 - student ID 1001 and 1002

1 1 June 06 30 November 06 1 - Student ID 1003

2 1 December 06 31 May 07 0 - no

3 1st June 07 1st November 07 1 - Student ID 1004 (1001 should not be taken to the top)

4 1st December 07 to 31 May 08 0 - no. They have all been included in the previous periods

could be done with a UNION ALL operation student_test-tables (and a join with the time table):

with

BaseData as)

Select * from student_test1

Union of all the

Select * from student_test2

Union of all the

Select * from student_test3

Union of all the

Select * from student_test4

)

,

min_values like)

Select student_id, min (exam_date) exam_date

of basedata

Student_id group

)

Select tp.id

tp.start_date

tp.end_date

count (mv.student_id) student_id

of time_period tp

left outer join

min_values mv

on (mv.exam_date between tp.start_date and tp.end_date)

Tp.id group

tp.start_date

tp.end_date

order of tp.id

;

I HAVE START_DA STUDENT_ID END_DATE

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

01.12.05 0 31.05.06 2

1 01.06.06 30.11.06 1

2 01.12.06 31.05.07 0

3 01.06.07 30.11.07 1

4 01.12.07 31.05.08 0

Concerning

Martin

Tags: Database

Similar Questions

  • Using the same virtual machine on two macs, but not at the same time

    Hello

    I searched this site and the Internet in general, but I couldn't find an answer to this question, so my apologies if this is requested before and if so, please point me to the answer.

    I have an iMac with Bootcamp with Windows 7 Professional x 64 partition and everything works fine.

    I would like to install 6 Fusion and create a virtual machine from the Bootcamp partition, try it for a while and then delete the Bootcamp partition. I found a complete documentation about this and I should be able to do this without any problems, except perhaps for the reactivation of Windows.

    Now the question: since I move sometimes, I would like to be able to move this virtual machine on a Macbook Pro, so I must not move file, sync, etc., and the virtual machine will not at the same time. I read that you use Move so the address UUID and Mac do not change, but I don't know if this applies to move the virtual machine to another computer. If my is:

    (1) is it possible?

    (2) what I have to buy a second copy of Fusion 6 or there is a player that will allow me to run the virtual machine on the macbook?

    Thank you

    Luciano

    I have experimented with a Windows 7 VM, copied (but I have 2 licenses of retail sales) a mini Mac Core 2 Duo to a Core i7 MacBook Pro retina: well, despite the different processor, he did not ask a reactivation, strangely, even after a few resets. Windows 7 so, seems at least to be quite "tolerant", on this front.

  • I would like to purchase a license for a team of three people. This means that they could use one of the applications on three different computers but not at the same time? Thank you very much

    Hello

    I would like to purchase a license for a team of 3 people ($ 49.99 / month).

    Could they use with this single license applications on three different computers (not at the same time).

    Thank you very much

    FC

    Hello Claudio,.

    Please check the link below for the terms of use:

    Licensing and terms of use | Adobe

    Kind regards

    Sheena

  • Free disc of Premiere Elements with a camera. The serial No. work provided with the first part, but not with the elements of the part. Why is this?

    Hi, I'm new to this bear so please with me. I have a free disc of Premiere Elements with a new canon camera and install it on my pc windows 8.1. After installation I have a shortcut for first elements and a shortcut for the elements, I guess that first for the video and photo elements. The drive came with a serial No. who worked with first, but when I opened elements, he asked for a serial No. but when I tried the same series only.  It says this serial No. is not valid for Adobe photoshop elements. I'm something wrong, I am missing a serial number, do I have to pay to use the side elements (photo editor), and if so I don't understand why he loaded the two programs on a disk I thought it was a big split in video and photo program.

    Help, please.

    First elements and Photoshop are separated with different serial numbers. Usually adobe up in the trial for the other disk. Are you sure you have PES as BEFORE? A PSE serial number starts with 1057.

  • Disable the menu bar, the option apears in my Firefox 3.6 X using Windows XP SP3, but not in the same version with Ubuntu 10.04

    With the help of dual boot OS, Windows XP SP3 / Ubuntu 10.04. Even Firefox v3.16.13. In windows, using the button display in the menu bar, I can't turn off the menu bar. You use Ubuntu, the same option is available in "display".
    I used "subject: Config" before, but I'm very careful and document all changes. Any time I need to access the menu items, using windows, I just use alt = _.

    In versions of Firefox 3.6 you can hide the bar of menus under Windows and not Linux. In Firefox 4 beta current versions you can hide the Menu bar and have the greyish Firefox button instead and use F10 to temporarily show the Menu bar, so you need to wait or try the beta version .

  • a computer can find the mx922, but not on the same network

    I installed the drivers on my computer tower and on the laptop and everything worked well. Today I went to print from the laptop and it says that the printer is not responding. I went to the tower and the Tower allows to print very well.  So I know that the printer works and talk to the network.

    The laptop is obviously the question.

    Did not uninstall the disks in windows 7 (on the laptop) but I wasn't going to screen printers and devices.  Then, I removed the printer from this screen and told to look for all new printers on the network.  It says that it cannot find.  The laptop can see my computer turn on the network, so I know that the network settings should be ok.

    I don't know where to go from here.

    Any help is appreciated.

    Andrew

    This does not solve the problem.

    Here's what did finally solve the problem.

    I closed the two Tower computers and the printer is off.

    Then pulled the power to the router. I left the modem cable.

    Then I started the router, once which has been fully booted up. Then I powered to the top of the tower and the laptop.

    Now, I went into the router and looked what devices were online and just watched the key info on them.  I don't have any changes.  Then have left.

    For some reason any printer showed up suddenly on the laptop.  Not sure why however.

  • We need Adobe Creative Cloud on several computers, but not at the same time.

    Only sporadic use would bear expensive to purchase 6 licenses.

    Adobe offers a package in which the license, for example, can only be used by one or two computers at the same time, but installed on each computer, at the cost of one or two licenses?

    It is quite awkward to make people change computer to use Adobe products.

    Thank you.

    I * think * this will answer your question

    Maximum activations exceeded subscription or product launch Cloud creatives

  • If I have the two LOV in the same table then how to connect when I select first and second LOV value also change?

    Mr President

    If I have the two LOV in the same table then how to connect when I select first and second LOV value also change?

    My two fields are FLOW AND DR_NAME

    FLOW = ACCT_ID

    DR_NAME = ACCT_NAME

    I created with success of LOV for these fields.

    First LOV gives acct_id in the debit field and second LOV gives the value of acct_name to dr_name.

    How can I report these lov, it's that when I change my acct_id then acct_name also change

    I have these two tables

    CREATE TABLE "NOM"  (
      "ACCT_ID" VARCHAR2(7) NOT NULL ENABLE, 
      "ACCT_NAME" VARCHAR2(50) NOT NULL ENABLE, 
      "O_BAL" NUMBER(13,2),
      CONSTRAINT NOM_PK PRIMARY KEY ("ACCT_ID")ENABLE
       
       );
    CREATE TABLE "VOUCHERDET" (
      "V_ID" VARCHAR2(9) NOT NULL ENABLE,
      "LINEITEM" NUMBER ,
      "DEBIT" VARCHAR2(7) , 
      "DR_NAME" VARCHAR2(50), 
      "CREDIT" VARCHAR2(7) , 
      "CR_NAME" VARCHAR2(50), 
      "PARTICULARS" VARCHAR2(100), 
      "AMOUNT" NUMBER(21,2),
    CONSTRAINT VOUCHERDET_PK PRIMARY KEY ("V_ID","LINEITEM")ENABLE, 
    CONSTRAINT PUR_SAL_LINE_POD_FK FOREIGN KEY(PROD_ID)
      REFERENCES PRODUCTS (PROD_ID)ENABLE,  
    CONSTRAINT VOUCHERDET_DEBIT_FK FOREIGN KEY ("DEBIT")
       REFERENCES "NOM" ("ACCT_ID") ENABLE, 
    CONSTRAINT VOUCHERDET_CREDIT_FK FOREIGN KEY ("CREDIT")
       REFERENCES "NOM" ("ACCT_ID") ENABLE,  
    CONSTRAINT VOUCHERDET_V_FK FOREIGN KEY ("V_ID")
       REFERENCES "VOUCHER" ("V_ID") ON DELETE CASCADE ENABLE
      );
    
    

    Concerning

    so, instead of this second ActId, choose ACCT_NAME:

  • I forgot my password for apple and have permission to stage the 2 and broken my old phone and do not have the same number of what I can do my account is already waiting to be reset, but it takes apple long to to deal with the what else is there to do?

    I forgot my password for apple and have permission to stage the 2 and broken my old phone and do not have the same number of what I can do my account is already waiting to be reset, but it takes apple long to to deal with the what else is there to do?

    You know the e-mail password what do you use? I lost over $ 30 on my old Apple ID because I couldn't get into the email and apple would not transfer my money to my new account.

  • After that installation of 9.3 iPad will not activate, it has been restored, but still not turn on. The first owner does not know the password

    After that installation of 9.3 iPad will not activate, it has been restored, but still not turn on. The first owner does not know the password

    And this is not recognitze by any device, computer or iPhone 6plus.

    If you or the original owner did not have the password no one here or at Apple can help you.

  • Pitch bend wheel on my pc - 300 midi keyboard Roland. The Modulation part works but when I try to pitch bend a note using the same logic of wheel just plays a continuous note. Can someone give me some advice please? Thank you

    Hi, I have a problem with my pitch bend wheel on my pc - 300 midi keyboard Roland. The Modulation part works but when I try to pitch bend a note using the same logic of wheel just plays a continuous note. Can someone give me some advice please? Thank you

    It's a delicate issue... like some patches cannot stipulate pitchbend...

    But to quickly test your pitchbend wheel actually works properly...

    Download the free lunch monitor...

    Snoize: MIDI Monitor

    Run and see if it sees pitchbend data sent by your keyboard... and therefore by logic.

  • I have an iphone 5s, but it does not load. Always stay at 1%. Also I rechangés my battery, but it's the same. What can I do? Please help me!

    I have an iphone 6s, but it won't work. Always stay ay 1%. Also I rechangés battery, but it's the same. What can I do? Please help me. IM from Albania and here do not have Apple shop. Help me! Thank you

    I asked that your post be moved to the correct forum. iPhone batteries are not replaceable by the user.

    Leo

  • My ipod 5th generation is stuck by resetting the settings and I tried holding the power and the "home" button but has just the same. Also, I tried to sync it upward, so I tunes but it has not been recognized and I can't answer on my ipod. Help, please!

    My iPod 5th generation is stuck by resetting the settings and I tried holding the power and the "home" button but has just the same. Also, I tried to sync it upward, so I tunes but it has not been recognized and I can't answer on my iPod. Help, please!

    Try the remaining shares of:

    - iOS: do not respond or does not light

    -Also try DFU mode recovery mode post-test

    How to put iPod touch / iPhone in DFU "Karthik doodles."

    -If failed and that you cannot completely turn completely the iOS device, leave the battery to drain completely. After loading a hour repeat the foregoing.

    -Try a different cable

    -Try on another computer

    S ' there is still not successful that usually indicates a hardware problem and an appointment at an Apple store Genius Bar is in order.

    Shop Apple Store - Genius Bar

  • Apple TV 4 will not play my movies that I had in itunes. It says unplayable format, but it is the same format that I use always and a lot of movies? What could this be?

    Apple TV 4 will not play my movies that I had in itunes. It says unplayable format, but it is the same format that I use always and a lot of movies? What could this be?

    This new IOS is bug.

    I had the same error message and tried to "create a different version" in Itunes.

    The ITunes says "this video is already formatted correctly."

    I tried to play again on the Apple TV and it worked then after a bit of buffering.

  • 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