Question

Not a programmer but using data.stackexchange.com. I'm querying the public SE data explorer and the column names that I'm specifying are invalid. Also, how do I specify Count (Posts) and Count (Votes)? Is anyone who queried data.se and knows the db schema able to help me correct this code?

Select Count (u.Id)
From Users u 
Left Join Posts p on u.Id = p.OwnerUserId
Left join SuggestedEdits e on u.Id = e.OwnerUserId
left join Votes v on u.Id = v.UserId
WHERE ((u.CreationDate BETWEEN 'qwerty' AND 'qwerty')
AND (p.CreationDate BETWEEN 'qwerty' AND 'qwerty')
AND (p.ClosedDate is null)
OR (e.CreationDate BETWEEN 'qwerty' AND 'qwerty'))
AND Count (Posts) = x
OR Count (Votes) = y
Group by u.CreationDate, p.OwnerUserId, UserTypeId, u.DisplayName, p.CreationDate
Was it helpful?

Solution

Did you try the Compose Query option found here. If you click that link it shows you the database schema on the right-hand side in the sidebar.

Note that the sidebar can be hidden, just click the link to show it again. Is that what you need?

EDIT

I am still not really sure what you are trying to do exactly. If I were in your position I would start off by running some simple queries of each individual table first. This way you can see what data is stored there.

Run this query and check out the results:

SELECT *
FROM Users
WHERE CreationDate BETWEEN '2012-06-01 08:00:00' AND '2012-06-02 09:00:00'

Run this query and check out the results:

SELECT *
FROM Posts
WHERE CreationDate BETWEEN '2012-06-01 08:00:00' AND '2012-06-02 08:10:00'

Run this query and check out the results:

SELECT *
FROM Votes
WHERE CreationDate BETWEEN '2012-06-01 08:00:00' AND '2012-06-02 08:10:00'

I'm not sure why you have included the SuggestedEdits table in your join as it does not appear you are using that table anywhere else. So leave it out.

Now after seeing what the data looks like you should be able to piece them together to find what you are after. Which I still don't know? Hopefully something like this will help get you started. This query will return some results but I'm not sure it is what you are after.

SELECT Count(u.Id), Count(p.Id), Count(v.Id)
FROM Users u
LEFT JOIN Posts p on u.Id = p.OwnerUserId
LEFT JOIN Votes v on u.Id = v.UserId
WHERE u.CreationDate BETWEEN '2012-06-01 08:00:00' AND '2012-06-02 09:00:00'
GROUP BY u.CreationDate, p.OwnerUserId, v.VoteTypeId, u.DisplayName, p.CreationDate
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top