Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Grouping as pair

Author  Topic 

jdrella17
Starting Member

3 Posts

Posted - 2012-09-28 : 21:05:32
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)

17689 Posts

Posted - 2012-09-28 : 23:41:57
how do you want the result to looks like ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jdrella17
Starting Member

3 Posts

Posted - 2012-09-29 : 00:08:27
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)

17689 Posts

Posted - 2012-09-29 : 00:16:11
probably just

ORDER BY CLASS ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jdrella17
Starting Member

3 Posts

Posted - 2012-09-29 : 00:55:19
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
   

- Advertisement -