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
 sql developer help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mikkel
Starting Member

Norway
1 Posts

Posted - 03/01/2011 :  11:23:23  Show Profile  Reply with Quote
i have task in sql, but i am not sure that is correct...

can you help me with seeing about this correct

A 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 1

Find the name and age of all John’s cousins. Order the list by age with the oldest first.

my answer

SELECT name, age
FROM 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
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 03/01/2011 :  11:44:10  Show Profile  Reply with Quote
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.

Cheers
MIK
Go to Top of Page

chriscairns
Starting Member

2 Posts

Posted - 05/30/2012 :  03:50:03  Show Profile  Reply with Quote
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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52323 Posts

Posted - 05/30/2012 :  16:05:29  Show Profile  Reply with Quote
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 correct

A 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 1

Find the name and age of all John’s cousins. Order the list by age with the oldest first.

my answer

SELECT name, age
FROM 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 correct

it should be

SELECT p1.name, p1.age
FROM person p
inner join relto r
on r.name1 = p.name
inner join person p1
on p1.name = r.name2
WHERE r.kind = 'cousins'

union all

SELECT p1.name, p1.age
FROM person p
inner join relto r
on r.name2 = p.name
inner join person p1
on p1.name = r.name1
WHERE r.kind = 'cousins'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52323 Posts

Posted - 05/30/2012 :  16:05:58  Show Profile  Reply with Quote
try similarly for other queries

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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