By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,196 Members | 973 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,196 IT Pros & Developers. It's quick & easy.

A SQL Question

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Jul 19 '05 #2

P: n/a
AK
"Telus" <sr*******@l3technology.com> wrote in message news:<_omNb.13141$wf1.11109@edtnps89>...
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.FIELD1<>RIGHT_SIDE.FIELD1
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.