Is it possible (and allowed) to get the number of all questions, answers, and comments for a specific Tag and publish them on a website?
-
9This info is readily available from the data dump and SEDE. Content is licensed as CC-by-SA so you can do anything you want with it. Just post a link to your SEDE query.– Hans PassantCommented Feb 8, 2016 at 10:26
-
@HansPassant thank you for that fast answer. The query basicly works, besides it returns 0 for quering the amount of questions. Would you like to take a quick look at it? Thank you very much! data.stackexchange.com/stackoverflow/query/433357/… (In the query i select only IronPython questions).– BendEgCommented Feb 8, 2016 at 10:58
4 Answers
There's an issue with the join you are using between Posts
and PostTags
, use: p.Id = t.PostId
:
Try this one: https://data.stackexchange.com/stackoverflow/query/edit/433365#resultSets
SELECT
Count(*) AS QuestionCount
FROM
Posts p
JOIN PostTags t on p.Id = t.PostId
WHERE
t.TagId = 1589
AND p.PostTypeId = 1 -- Questions
Edit:
As stated in the comments by Conrad Frix:
...the tag table has a count that represents the question count e.g.
SELECT Count From Tags Where TagName = 'sql'
-
Do you know, if it is possible to embed those result in an external webpage?– BendEgCommented Feb 8, 2016 at 20:46
-
-
@jimtollan, Unfortunately, that would not work, as SE prevents embedding their sites (incl Data.SE) in an iframe, plus there's a captcha, so no embedding possible. The only way would be just to put the information wherever it's needed manually, and update manually, and periodically. Commented Feb 9, 2016 at 12:19
-
-
-
@Conrad, true, you can do it with with the API - however if you want to do it on the web, it may be more trouble than it's worth, due to JavaScript same origin policy, thus requiring you to set up a server-side "proxy" of some kind. Good point though, upvoted. Commented Feb 9, 2016 at 20:56
-
@JonasCz The usage section here indicates that Cross origin calls are accounted for Commented Feb 10, 2016 at 14:15
-
1@Tanner minor quibble on the sql.. the tag table has a count that represents the question count e.g.
SELECT Count From Tags Where TagName = 'sql'
Commented Feb 10, 2016 at 14:16 -
@ConradFrix good point, I didn't look at it in too much detail, just noticed that the join was wrong in the query he posted.– TannerCommented Feb 10, 2016 at 14:18
The following SEDE Query returns, for posts in a specific tag, the counts for questions, answers, comments, views and bookmarked. You can select the tag you're interested in as a parameter
select sum( case when posttypeid = 1 then 1 else null end) [Questions]
, sum( case when posttypeid = 2 then 1 else null end) [Answers]
, sum( case when posttypeid in (1,2) then 1 else null end) [Total]
, sum( case when posttypeid = 1 then commentcount else 0 end) [Q-cmts]
, sum( case when posttypeid = 2 then commentcount else 0 end) [A-cmts]
, sum( case when posttypeid in (1,2) then commentcount else 0 end) [Tot-cmts]
, sum( case when posttypeid = 1 then cast(Favoritecount as bigint) else null end) [Tot-Bookmarked]
, sum( case when posttypeid = 1 then cast(Viewcount as bigint) else null end) [Tot-Views]
from posts p
inner join posttags pt on pt.postid = coalesce(p.parentid, p.id)
inner join tags t on t.id = pt.tagid
where t.tagname = ##tag:string?ironpython##
When run today this is your result:
If you want to automate this result you would need to script that, for example by using a technique mentioned in How to download the CSV result of the same Data Explorer query agains different Stack Exchange sites?
Keep in mind SEDE is updated once a week on Sunday.
Give a big shout-out to Monica Cellio for the awesome SEDE Tutorial she wrote.
Say "Hi" in SEDE chat.
You can use the /tags/{tags}/info StackExchange API and then get the count out of the JSON result
For example passing SQL in for the tag for stackoverflow site gives this result
{
"items": [
{
"has_synonyms": true,
"is_moderator_only": false,
"is_required": false,
"count": 314791,
"name": "sql"
}
],
"has_more": false,
"quota_max": 10000,
"quota_remaining": 9989
}
The first two things can be answered without data.SE. Just search for [tagname] is:question
and [tagname] is:answer
and check the result count.