SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Grouping as pair
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jdrella17
Starting Member

3 Posts

Posted - 09/28/2012 :  21:05:32  Show Profile  Reply with Quote
I am fairly new to SQL Server and I am having some trouble pairing common fields as pairs. Here is the example of the problem: List Part_Num, "Description", and Class for each pair of parts that are in the same class. (EX...AT94 and FD21 are a pair because they are in the same class-HW). Here is a partial table for parts.

PART_NUM DESCRIPTION CLASS
AT94 Iron HW
BV06 Home Gym SG
CD52 Microwave Oven AP
DL71 Cordless Drill HW
DR93 Gas Range AP
DW11 Washer AP
FD21 Stand Mixer HW
KL62 Dryer AP
KT03 Dishwasher AP
KV29 Treadmill SG

Any advice or help would be greatly appreciated. A brief explanation would be fantastic. Thank you all in advance.

khtan
In (Som, Ni, Yak)

Singapore
17587 Posts

Posted - 09/28/2012 :  23:41:57  Show Profile  Reply with Quote
how do you want the result to looks like ?


KH
Time is always against us

Go to Top of Page

jdrella17
Starting Member

3 Posts

Posted - 09/29/2012 :  00:08:27  Show Profile  Reply with Quote
You know, that is a great question. I guess I should have asked that because thinking about it, I am not even sure. I originally was thinking on using GROUP BY, but then that would list all items in class HW and not pairs. The more I read this question, the more confused I get. If you have any suggestions, feel free to let me know. Honestly, I am not even understanding what it is asking. If you are wondering, yes, this is for an ungraded challenge assignment. It is just starting to consume me so now I need to know the output
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17587 Posts

Posted - 09/29/2012 :  00:16:11  Show Profile  Reply with Quote
probably just

ORDER BY CLASS ?


KH
Time is always against us

Go to Top of Page

jdrella17
Starting Member

3 Posts

Posted - 09/29/2012 :  00:55:19  Show Profile  Reply with Quote
I figured it out and I did group it by class. For anyone that is curious, here it is.

select a.Part_Num, a."description", a.class, b.part_num, b."description", b.class
from PART a, part b
where a.CLASS = b.CLASS
and a.PART_NUM < b.PART_NUM
order by a.class, b.class ;

Thanks for the help. I know it wasn't much, but you did attempt to help me out. Very much appreciated.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000