Stack Exchange Data Explorerは、Stack Exchange データベースに対する SQL クエリを許可します。私はこれを試しました—</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;
—しかし、サイトは私に言った
')' 付近の構文が正しくありません。「wh_score」付近の構文が正しくありません。「wh_answers」付近の構文が正しくありません。
理由がわかりません。誰でも助けてもらえますか?
私が試したこと、無駄に:
datepart(month,CreationDate)
の代わりにmonth(CreationDate)
(および同様にyear
)- エイリアスに対して明示的
as
(その後、3 つのエラーのうち後半の 2 つは、エイリアスではなく「at」について不平を言いました) - 組み込み関数名ではないエイリアス
left(Title,2)
それ以外のlower(left(Title,2))
and
sで結合された 4 つのものの最初の 2 つと最後の 2 つを括弧で囲みます。u.
サブクエリの列名を明示する