Getting count of related tags(获取相关标签的计数)
问题描述
我最近问了这个问题以获取 Stack Overflow 中的相关标签:要获取的查询是什么?相关标签"就像堆栈溢出一样
I recently asked this question to get related tags like in Stack Overflow: what is the query to get "related tags" like in stack overflow
我想在 Stack Overflow 中显示计数,所以对于每个相关标签,第一个标签的问题中其他标签的计数是多少?
I would like to show the count like in Stack Overflow, so with each related tag, what is the count of this other tag on questions with the first tag?
因为这些查询都有不同的内容.我不认为这是可能的,但显然 Stack Overflow 必须这样做(除非他们在多个查询中这样做.)
Because these queries all have distinct in them. I don't think it is possible but obviously Stack Overflow must be doing this (unless they are doing this in multiple queries.)
有什么方法可以在同一个查询中获取所有相关标签的计数,还是必须在单独的查询中完成?
Is there any way to get count of related tags all in the same query or must it be done in separate queries?
推荐答案
可以搜索相关标签的总数:
You could search for the total count of related tags:
SELECT t2.tagname, count(distinct tb2.linkid) as RelatedLinkCount
FROM TAGS t2
JOIN TAGS_BRIDGE tb2 on t2.tagid = tb2.tagid
JOIN TAGS_BRIDGE tb1 on tb2.linkid = tb1.linkid
JOIN TAGS t ON t.id = tb1.tagid
WHERE t.tagname = 'tag3'
GROUP BY t2.tagname
从标签名称 (t) 开始,查找该标签的链接 (tb1),然后查找共享链接的标签 (tb2).它会查找相关标签的名称(t2)并完成 :) 甚至不需要加入 LINKS 表.
Starting with the tag name (t), it looks for links for that tag (tb1), then it looks for tags that share a link (tb2). It looks up the name for the related tags (t2) and it's done :) No need to even join the LINKS table.
这篇关于获取相关标签的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取相关标签的计数
基础教程推荐
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 无法解决整理冲突 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
