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.
Author |
Topic |
mikkel
Starting Member
1 Post |
Posted - 2011-03-01 : 11:23:23
|
i have task in sql, but i am not sure that is correct...can you help me with seeing about this correctA very simple model for social networking like for instance Facebook could be modeled by these two relations:person(name, age, gender)relto(name1, name2, kind)where we assume that a name uniquely identify persons and persons can be related to each other in different kinds of relationships, i.e. friends, married, colleagues, schoolmates, etc.qeustion 1Find the name and age of all John’s cousins. Order the list by age with the oldest first.my answer SELECT name, ageFROM person WHERE kind = cousins;I have som more qeustions you could help me with Find each friend of John that is not a colleague.Find the number of relations for each kind of relationship for John, Joe, and Nelly.What is the average number, taken over all persons, of relations in each kind of relationship?mikkel |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-03-01 : 11:44:10
|
come up with sample data of your table, identify the primary key and foreign key relationship/column of both and the desired output you are looking for in light of your sample info.CheersMIK |
|
|
chriscairns
Starting Member
2 Posts |
Posted - 2012-05-30 : 03:50:03
|
Facebook is a great way to stay in touch with those you care about, but it is also a great tool you can use to market your business.unspammed |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-30 : 16:05:29
|
quote: Originally posted by mikkel i have task in sql, but i am not sure that is correct...can you help me with seeing about this correctA very simple model for social networking like for instance Facebook could be modeled by these two relations:person(name, age, gender)relto(name1, name2, kind)where we assume that a name uniquely identify persons and persons can be related to each other in different kinds of relationships, i.e. friends, married, colleagues, schoolmates, etc.qeustion 1Find the name and age of all John’s cousins. Order the list by age with the oldest first.my answer SELECT name, ageFROM person WHERE kind = cousins;I have som more qeustions you could help me with Find each friend of John that is not a colleague.Find the number of relations for each kind of relationship for John, Joe, and Nelly.What is the average number, taken over all persons, of relations in each kind of relationship?mikkel
your query is not correctit should beSELECT p1.name, p1.ageFROM person pinner join relto ron r.name1 = p.nameinner join person p1on p1.name = r.name2WHERE r.kind = 'cousins'union allSELECT p1.name, p1.ageFROM person pinner join relto ron r.name2 = p.nameinner join person p1on p1.name = r.name1WHERE r.kind = 'cousins' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-30 : 16:05:58
|
try similarly for other queries------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|