The Stack Exchange Data Explorer allows SQL queries against a Stack Exchange database. I tried this one —</p>
select
month(CreationDate) month,
year(CreationDate) year,
sum(lower(left(Title,2))='wh')/count(*) wh,
(select sum(Score)/count(*)
from Posts u
where month(CreationDate)=month(t.CreationDate)
and year(CreationDate)=year(t.CreationDate)
and lower(left(Title,2))='wh'
and PostTypeId=1 -- question
) wh_score,
sum(Score)/count(*) score,
(select sum(AnswerCount)/count(*)
from Posts u
where month(CreationDate)=month(t.CreationDate)
and year(CreationDate)=year(t.CreationDate)
and lower(left(Title,2))='wh'
and PostTypeId=1 -- question
) wh_answers,
sum(AnswerCount)/count(*) answers
from Posts t
where PostTypeId=1 -- question
group by month,year;
— but the site told me
Incorrect syntax near ')'. Incorrect syntax near 'wh_score'. Incorrect syntax near 'wh_answers'.
and I cannot figure out why. Can anyone help, please?
Things I've tried, to no avail:
datepart(month,CreationDate)
instead ofmonth(CreationDate)
(and likewise foryear
)- explicit
as
for aliases (then the latter two of the three errors complained about 'at' rather than about the aliases) - aliases that aren't built-in function names
left(Title,2)
instead oflower(left(Title,2))
- putting parentheses around the first two, and around the last two, of the four things joined by
and
s - explicit
u.
for column names in the subqueries