mysql - How can I get top users in specific tags? -
i have function this:
create definer=`root`@`localhost` function `user_top_tags`(`user_id` int, `tags_num` tinyint(1)) returns varchar(50) charset utf8mb4 no sql begin declare top_tags varchar(50); select substring_index(group_concat(x.name order x.tag_score desc separator ','), ',', tags_num) top_tags ( select t.name, sum(r.score) tag_score reputations r join qanda_tags qt on qt.qanda_id = r.question_id join tags t on t.id = qt.tag_id r.owner_id = user_id group t.name ) x; return top_tags; end
and call this:
select u.name, user_top_tags(u.id, 3) users u 1;
and returns list of users top 3 tags. this:
+--------+-----------------+ | jack | php,oop,mysql | | martin | css,js,html | | peter | jquery,js,react | +--------+-----------------+
now want users has active in specific tags. top users page in (which javascript
tag, want list of users in multiple tags, in ('css','html')
).
now should join on query? or should modify function? have idea how can that?
select substring_index(group_concat(x.name order x.tag_score desc separator ','), ',', 3) top_tags,x.username ( select u.name username,t.name, sum(r.score) tag_score reputations r join qanda_tags qt on qt.qanda_id = r.question_id join tags t on t.id = qt.tag_id inner join users u on u.id = r.owner_id group t.name,u.name having u.active < 10 ) x;
instead of writing function,you can achieve same business logic using simple query. go query .
you can try above query.
here had consider have column specify user active how many days.
hope you.
Comments
Post a Comment