A SQL Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Telus

    A SQL Question

    A SQL question

    Hi Everybody,
    Imagine I have a file with 7 records
    and two fields with these data:

    Record1--Field1=1--Field2=10:45pm
    Record2--Field1=1--Field2=10:46pm
    Record3--Field1=2--Field2=10:47pm
    Record4--Field1=2--Field2=10:48pm
    Record5--Field1=2--Field2=10:49pm
    Record6--Field1=1--Field2=10:50pm
    Record7--Field1=1--Field2=10:51pm

    How can I write a SQL to give me
    Records 2,5 and 7, fields 1 and 2?

    I mean I sort records base on field 2 then
    for each change on field1, I need one record
    that can be max or min of field2,
    I couldn't use group by because group by consider
    all record with field1 value of 1 one group but
    I need one record for each changes on record1,

    Thank you in advance - Sasan


  • Ana C. Dent

    #2
    Re: A SQL Question

    Telus wrote:
    A SQL question
    >
    Hi Everybody,
    Imagine I have a file with 7 records
    and two fields with these data:
    >
    Record1--Field1=1--Field2=10:45pm
    Record2--Field1=1--Field2=10:46pm
    Record3--Field1=2--Field2=10:47pm
    Record4--Field1=2--Field2=10:48pm
    Record5--Field1=2--Field2=10:49pm
    Record6--Field1=1--Field2=10:50pm
    Record7--Field1=1--Field2=10:51pm
    >
    How can I write a SQL to give me
    Records 2,5 and 7, fields 1 and 2?
    For what school, course & instructor was this homework assigned?
    Based upon what criteria/logic are records 2,5,7 the "correct" answer?

    Does the answer change (if so to what?) & why for the following records:

    Record1--Field1=1--Field2=10:51pm
    Record2--Field1=1--Field2=10:50pm
    Record3--Field1=1--Field2=10:46pm
    Record4--Field1=1--Field2=10:45pm
    Record5--Field1=2--Field2=10:49pm
    Record6--Field1=2--Field2=10:47pm
    Record7--Field1=2--Field2=10:48pm


    Comment

    • AK

      #3
      Re: A SQL Question

      "Telus" <sraisdana@l3te chnology.comwro te in message news:<_omNb.131 41$wf1.11109@ed tnps89>...
      A SQL question
      >
      Hi Everybody,
      Imagine I have a file with 7 records
      and two fields with these data:
      >
      Record1--Field1=1--Field2=10:45pm
      Record2--Field1=1--Field2=10:46pm
      Record3--Field1=2--Field2=10:47pm
      Record4--Field1=2--Field2=10:48pm
      Record5--Field1=2--Field2=10:49pm
      Record6--Field1=1--Field2=10:50pm
      Record7--Field1=1--Field2=10:51pm
      >
      How can I write a SQL to give me
      Records 2,5 and 7, fields 1 and 2?
      >
      I mean I sort records base on field 2 then
      for each change on field1, I need one record
      that can be max or min of field2,
      I couldn't use group by because group by consider
      all record with field1 value of 1 one group but
      I need one record for each changes on record1,
      >
      Thank you in advance - Sasan

      1. add ROWNUM to select list
      2. Join adjacent rows, it's easy to do it on ROWNUM
      3. add a condition LEFT_SIDE.FIELD 1<>RIGHT_SIDE.F IELD1

      Comment

      Working...