The image shows the structure of my table. The first line means tutorB gives 10 marks to studentD. The second line means tutorE does not give any marks to studentD yet.
How can I generate the following table? I have referenced another post in stackoverflow.com. Collaborative filtering in MySQL? Yet, I am still quite confused.
From the image shown above, o means recommended, which the rate is higher than or equal to 7; x means not recommended, which the rate is less than 7.
For example, the tutorB give studentD 10 marks, therefore, from the second line in the image, we can see there is a "o" in column StudentD. ( And other three rows's data are just randomly assigned now.)
Now, if I want to recommend a student for Tutor A. The ranks ( or similarity) of TutorB, C and D are 0,2 and 3 respectively.
How can I generate a SQL such that I can able to convert the rate to "o" and "x" and calculate the rank. And, the most important, I want to recommend StudentH to TutorA as from the image.
How should I modify the code from the previous post? And, if my idea mentioned above correct?
Thanks.
============================================================================
EDITED
I have the following data in the database. The first row means 10 marks is given by tutorA to studentC.
I convert it as another table for a better understanding. v
is the value of Rate.
create temporary table ub_rank as
select similar.NameA,count(*) rank
from tbl_rating target
join tbl_rating similar on target.NameB= similar.NameB and target.NameA != similar.NameA
where target.NameA = "tutorA"
group by similar.NameA;
select similar.NameB, sum(ub_rank.rank) total_rank
from ub_rank
join ub similar on ub_rank.NameA = similar.NameA
left join ub target on target.NameA = "tutorA" and target.NameB = similar.NameB
where target.NameB is null
group by similar.NameB
order by total_rank desc;
select * from ub_rank;
The code above is referenced from Collaborative filtering in MySQL?. I have a few questions.
There are 2 parts in the SQL. I can select * from the first part. However, if I enter the whole SQL as shown above, the system alerts
Table 'mydatabase.ub' doesn't exist
How should I modify the code?The code will find the similarity. How should I change the code, such that if the marks are less that 7, it changes to
o
, else change tov
, and count the similarity of a given user?