2011-05-20 53 views
1
amydeshane 0.180751 games 
amydeshane 0.178772 video 

我需要一個查詢來查找像這樣的實例,其中用戶有一個以上的標記。在一個定義的集合中查找具有公共標記的用戶的sql查詢

例如where Category in ('games','video','flash')

我想,更多的標籤是在共同與設定的越高他們的排名。比如'amydeshane'應該有matching_terms = 2

有什麼想法嗎?

現在這是我的查詢,但它不給我我需要的,因爲我想那是amydeshane「被排名更高,因爲它含有更多的標籤相匹配的結果

SELECT  TOP (10) Username, tfidf AS TotalUsed 
FROM   UserInfo 
WHERE  (Category IN ('video', 'graphics', 'editor', 'games', 'youtube')) 
GROUP BY Username, tfidf 
HAVING  (COUNT(Username) > 1) 
ORDER BY TotalUsed DESC 

這些結果如下:

kingjames23 0.626885 
F_David 0.406635 
bjhscomputers 0.401741 
jaw6 0.347777 
lkw5151604 0.257147 
anniemalahus 0.242461 
opusfluke 0.240047 
pporto 0.235550 
amydeshane 0.180751 
amydeshane 0.178772 

回答

3
select username, sum(tfidf) as totalused 
from userinfo 
where category in(...) 
group by username 
having count(category) > 1 
order by sum(tfidf) desc 
+0

感謝它的工作:) – michelle 2011-05-20 11:08:30

1

我從你的結果猜測,每個其他用戶的只有1個標籤?

我不知道這是否是你想要的,但你可以做用戶名現場和totalused場之和的個性化......

SELECT TOP (10) Username, COUNT(Username) AS TagCount, SUM(tfidf) AS TotalUsed 
FROM UserInfo 
WHERE (Category IN ('video', 'graphics', 'editor', 'games', 'youtube')) 
GROUP BY Username, tfidf 
HAVING (COUNT(Username) > 1) 
ORDER BY COUNT(Username),TotalUsed DESC 
相關問題