Click here to Skip to main content
16,004,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two tables:

SQL
1. 
userInfo
(
ScreenName varchar(20),   (pk)
City varchar(50),
Gender varchar(6)
)

ScreenNameCityGenderAge
MiteshMumbaiMale23
VarunDelhiMale22
RaviAgraMale24
KarishmaBangaloreFemale21
PurvaHyderabadFemale19


SQL
2.
friendList
(
senderScreen varchar(20),  (fk userInfo(ScreenName))
receiverScreen varchar(20),  (fk userInfo(ScreenName))
senderRated int,
receiverRated int
)


senderRated column stores the rating that receiver gave to sender
and
receiverRated column stores that rating that sender gave to the receiver.


senderScreenreceiverScreensenderRatedreceiverRated
MiteshVarun54
MiteshRavi12
VarunKarishma2NULL


I want a query to give the Output like:


ScreenNameGenderCityRating
VarunMaleDelhi3
MiteshMaleMumbai3
RaviMaleMumbai2
KarishmaFemaleBangaloreNULL
PurvaFemaleHyderabadNULL
Posted
Updated 20-Jun-12 21:21pm
v3
Comments
OriginalGriff 21-Jun-12 3:29am    
How are you working out the rating? It isn't immediately obvious from the number examples you give.
varun491 21-Jun-12 3:32am    
when you see the table 'friendList'
To calculate rating for Varun:
in first row Varun is in receiver column so i check the value in receiverRated for 1st row . i.e 4

Then in third row varun is the sender so I check the rating for varun in SenderRated column for this row . i.e 2

Then I add the ratings and divide by the count of the rates
i.e. 4+2/2
varun491 21-Jun-12 8:54am    
not solved yet..
can anyone help.

1 solution

use concept of 'Join' on your table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900