Re: SQL for Youngest Sibling or Only Sibling



On Thu, 6 Apr 2006 06:26:02 -0700, Bonnie wrote:

Given the following tables:

PERSONS table with a (unique PERSON_ID), SIBLING_ID, BIRTH_DATE, SURNAME,
FIRST_NAME

STUDENT_REGISTRATIONS table with a (concatenated key PERSON_ID,
SCHOOL_YEAR, SCHOOL_CODE )

I need to select students with a specific school_code = 'NORT' and school
year = '20052006' who have either no siblings (sibling_id will be null) and
youngest student of a sibling group (note surname may not be same as another
family member and there maybe twins having the same birthday.) All siblings
in the same family unit have a unique sibling_id.
For example:

person_id sibling_id birth_date Surname First_Name
1 20 1995-05-05 Doe John
2 null 1992-01-01 Smith Betty
3 20 2000-06-06 Doe Jane
4 20 1999-01-07 Doe Bill
5 30 1998-07-05 Twins Sally
6 30 1998-07-05 Twins Bob
7 30 1996-12-12 Twins-Not Sally

The result set should return (Note: min person_id of twins):
person_id sibling_id birth_date Surname First_Name
3 20 2000-06-06 Doe Jane
2 null 1992-01-01 Smith Betty
5 30 1998-07-05 Twins Sally

Hi Bonnie,

Do I smell a school assignment?

Anyway, the specifications you've given are incomplete. You write that
twins might have the same birthday, but you fail to tell how to select
the twin to put in the result set. In other words, why was Sally Twins
included in the result above, and not Bob Twins?

For better help, please post CREATE TABLE and INSERT statements, as
explained at www.aspfaq.com/5006.

--
Hugo Kornelis, SQL Server MVP
.



Relevant Pages

  • Re: G.M.T. Tuesday 14th March 2006
    ... Maybe get a photo or two while we are ... Can I come round to your place in summer if I want a bath Mike? ... Morning mike and all, happy birthday to the twins, hope you get your photos ...
    (uk.people.silversurfers)
  • Re: Please help evaluate/recover from mistakes
    ... mommie on sabbatical for the weekend. ... year olds. ... My kids birthday is ... I have 4-year old twins whose birthdays are November 8th! ...
    (rec.crafts.brewing)
  • Re: Please help evaluate/recover from mistakes
    ... year olds. ... My kids birthday is ... I wonder if it is something in the homebrew. ... I have 4-year old twins whose birthdays are November 8th! ...
    (rec.crafts.brewing)
  • Re: Way OT: The Boys Are Here!
    ... twins run in families. ... women were conceiving almost up to menopause, having larger families ... Buy every children's birthday cake ever printed - you need inspiration ...
    (rec.food.cooking)
  • Re: Another Twirly GMT Monday 10th December 2007
    ... A very Happy Birthday to the twins, ... Have a lovely time with them and I look foward to the piccies. ... Probably have to stop at Asda to get an extra little something for the twins? ...
    (uk.people.silversurfers)