| Author |
Topic |
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-01-20 : 04:47:16
|
Hello I have alot of memebers in my database.Now I made a system where you can select words that match your profile. Like "programming", "websites", "reading", "sport", etc!these words you can place under diverent types like. weak, strong, strongest. So If you dislike sport you place sport in the field weak. Do you really like programming you place it under strongest.tblkeywordsidUseridKeyWordtype1 1 strong1 2 strongest1 5 weak2 1 strong2 3 weak3 2 strongest4 2 strong4 5 weaketc.Now I want to match people with the most similarity types to each other. Can somebody tell me how I can do this?ThanxxBjorn p.s. if you need some more info just let me know! |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2004-01-20 : 06:27:42
|
| On first glance, I'm thinking you may find this easier if you have another table that assigns a numeric value to the "Strong" "Weak" etc categories. You can then use a CASE statement with the difference in numeric value per keyword to determine the match. Yes.-------Moo. :) |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-01-20 : 06:46:01
|
| Pretty simple.tblkeywords >> idUser, idKeyWord, typeNoselect t1.idUser idUser1, t2.idUser idUser2from tblkeywords t1 inner join tblkeywors t2 ont1.idUser<t2.idUser and t1.idKeyWord=t2.idKeyWordgroup by t1.idUser, t2.idUserhaving sum(abs(t1.typeNo-t2.typeNo)) <= {here a number from 0 to 20}table types:typeNo ~~ type0 ~~~ disgust1 ~~~ neutral2 ~~~ weak3 ~~~ strong4 ~~~ strongest |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-01-20 : 08:07:33
|
| Oke thanxx but I dont really understand your query "Stoad", because I want to match let say idUser = 87 with the other users in my database. And I cannot enter an username in your query.And what happend if there is no one exactly the same so one user has "sport - strong" and the other "sport - strongest" and the rest of the users have "sport - weak". Than I want the user most near also be in the list.Hope you can help me out,thanxxBjorn |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-01-20 : 09:22:08
|
| Less difference of numeric presentations of types - more common in a given interest.Then I just sum up all these differences (more correctly, their absolute values). |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-01-20 : 09:31:16
|
| definitely do not use this "multiple field" method -- use 1 column called "interest", and another for "interest-level", which could be either text or a numeric value. if it is a text value, use another table to list all possible values and perhaps a numeric representation for each.- Jeff |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-01-20 : 09:59:45
|
| jsmith8858 nice amount of postings :-) 2004 (the year whe live in!)Yes I made a change now to the database. I have only numbers in my tblkeywords.Stoad i understand that you sum up all those values but its not correct because let sayUser1:sport - 0 (weak)computers - 3 (strongest)Sum = 3User2: sport - 3computers - 0Sum = 3So you say that those people have the same interests? I dont think so!Hope there is an other solution to my problem.ThanxxBjorn |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-01-20 : 10:45:30
|
| A dating service for the Netherlands? Go figure...http://www.cia.gov/cia/publications/factbook/geos/nl.htmlAnyway...you need SUM by catgeory and/or relate categories to each other with a super type...so that you can group like things together..Ballet, Classical music, jazz, ect group togetherGrung, dive bars, clubing, ect group together...How you make that disticntion is up to you...What about the cross lifestyle people...Brett8-) |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-01-20 : 13:13:04
|
ebs, neutty, did you notice in my dull query this (in ON part):and t1.idKeyWord=t2.idKeyWord ?And you say that I compare interest to tequila (cactusovoe poilo)against interest to dry stoads collecting?User1:sport - 0 (weak)computers - 8 (strongest)Sum = 8User2: sport - 3computers - 4Sum = 7In fact, your sample goes like this: sum = abs(0-3) + abs(8-4) = 7,and less this sum - more close men in their interests. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-01-20 : 13:29:16
|
| The Freaky Yak Linguist strikes again!Tara |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-01-20 : 13:42:49
|
| ok I just noticed .. I thought that idKeyWords are ids of interests.Strangely you constructed your table. Let's start from this table:t: userid, interestid, interestdegreehere interestids are numeric codes of all interests: sport, web and so on,interestdegrees are numeric codes of all types of interest: weak, strong and so on.Lets investigate the user with userid=5 (e.g.):select t2.userid as MatchingUser,sum(abs(t1.interestdegree-t2.interestdegree)) as HowCloseHeIsfrom t t1 inner join t t2 on t1.interestid=t2.interestidwhere t1.userid=5 and t2.userid<>5group by t2.useridhaving sum(abs(t1.interestdegree-t2.interestdegree)) <= 3 (for example)order by 2, 1 |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-01-21 : 04:57:39
|
Oke it works Great!I only do not understand the result idUser idKeyWord type1 2 11 1 12 3 23 3 23 2 24 1 1If I do a search for user 1 I get this as result:MatchUser HowClosHeIs4 03 1So is user 4 closer or user 3? I think user 4 because the have one exact the same match.(1 - 1)Can you also limit the amount of results it will give?Thanxx for all the great help!CyaBjorn |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-01-21 : 05:35:11
|
| Hi neut!Yes, you're right upon the 0 and 4 values of HowCloseHeIs (you may thinkof this field as if it is a distance between 2 men). How you can limit the result.There are two ways:1. by decreasing the number from HAVING sum(... ...) <= 3 (put here 0instead of 3 and you'll get all absolute matches of a given user).2. by adding into the query TOP N predicate, like this: select TOP 4 ... ...By this you'll get only 4 the most close matches for a user in subject. |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-01-21 : 06:13:09
|
| select TOP4 t2.userid as MatchingUser,sum(abs(t1.interestdegree-t2.interestdegree)) as HowCloseHeIsfrom t t1 inner join t t2 on t1.interestid=t2.interestidwhere t1.userid=5 and t2.userid<>5group by t2.useridhaving sum(abs(t1.interestdegree-t2.interestdegree)) <= 3 (for example)order by 2, 1This is not working :(I think Its have to be something with LIMIT 0, 3Because this works: SELECT * from tblusers LIMIT 0, 3ThanxxBjorn |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-01-21 : 07:11:23
|
| Hm.. what does "This is not working" mean? More info need. |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-01-21 : 07:20:30
|
| I get an error that my sql statement is not correct.hope this makes any sens! |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-01-21 : 08:05:17
|
| and what is the error message?maybe you wrote TOP4 instead of TOP 4? |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-01-21 : 08:37:31
|
| You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 't2.idUser AS MatchingUser, SUM(ABS(t1.interestdegree-t2.interestdegree)) AS HAnd I wrote in my message TOP4 but in the query its TOP 4I think Top 4 is not a mysql variable the have the limit 0,4 option. |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-01-21 : 08:49:06
|
| neut, old bean, I never saw that MySQL,not to mention its f**king manual.. lol.... |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-01-21 : 12:12:35
|
| neutcomp, this is a SQL Server site. You'll need to find a MySQL forum.You've currently got 69 posts. Have all of your questions been MySQL related?Tara |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-01-21 : 13:10:31
|
But this is the best forum ever!! Here the help you 100%No I am not going away, sorry And the answer fit also mysql, not only sqlserver or something else.Ofcours not everything works for mysql but I always have simpel question.CyaBjorn |
 |
|
|
Next Page
|