sql - syntax error in Data Explorer -


the stack exchange data explorer allows sql queries against stack exchange database. tried one —

select   month(creationdate) month,   year(creationdate) year,   sum(lower(left(title,2))='wh')/count(*) wh,   (select sum(score)/count(*)    posts u    month(creationdate)=month(t.creationdate)      , year(creationdate)=year(t.creationdate)      , lower(left(title,2))='wh'      , posttypeid=1 -- question   ) wh_score,   sum(score)/count(*) score,   (select sum(answercount)/count(*)    posts u    month(creationdate)=month(t.creationdate)      , year(creationdate)=year(t.creationdate)      , lower(left(title,2))='wh'      , posttypeid=1 -- question   ) wh_answers,   sum(answercount)/count(*) answers posts t posttypeid=1 -- question group month,year; 

— site told me

incorrect syntax near ')'. incorrect syntax near 'wh_score'. incorrect syntax near 'wh_answers'.

and cannot figure out why. can help, please?


things i've tried, no avail:

  • datepart(month,creationdate) instead of month(creationdate) (and likewise year)
  • explicit as aliases (then latter 2 of 3 errors complained 'at' rather aliases)
  • aliases aren't built-in function names
  • left(title,2) instead of lower(left(title,2))
  • putting parentheses around first two, , around last two, of 4 things joined ands
  • explicit u. column names in subqueries

  1. you can't group alias, need specify computed column
  2. this not allowed : sum(lower(left(title,2))='wh'). have convert case when operator.

here corrected query (that gives timeout):

select     month(creationdate) month   , year(creationdate) year   , sum(case when lower(left(title,2))='wh' 1 else 0 end)/count(*) wh   , (select sum(score)/count(*)    posts u    month(creationdate)=month(t.creationdate)      , year(creationdate)=year(t.creationdate)      , lower(left(title,2))='wh'      , posttypeid=1 -- question   ) wh_score,   sum(score)/count(*) score,   (select sum(answercount)/count(*)    posts u    month(creationdate)=month(t.creationdate)      , year(creationdate)=year(t.creationdate)      , lower(left(title,2))='wh'      , posttypeid=1 -- question   ) wh_answers,   sum(answercount)/count(*) answers posts t posttypeid=1 -- question group month(creationdate), year(creationdate); 

what trying query?


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -