2 つのテーブルがq1dataありq1lookup、postgres データベースにあります。q1data3 つの列 ( postid、reasonid、other) をq1lookup含み、2 つの列 ( reasonid、 ) を含みますreason。
reasonid4 つの列 ( 、、、、 )reasonを含むビューを作成しようとしていcountますpercentage。countはそれぞれの数であり、それぞれreasonを合計で割るpercentage必要があります(つまり、合計行の場合)。countcount(*) from q1datareasonid
しかし、エラーが発生し、構文エラーが近くにあると表示されますcount(*)。以下は私が使用しているコードです。助けてください。
select
cwfis_web.q1data.reasonid AS reasonid,
cwfis_web.q1lookup.reason AS reason,
count(cwfis_web.q1data.reasonid) AS count,
round(
(
(
count(cwfis_web.q1data.reasonid)
/
(select count(0) AS count(*) from cwfis_web.q1data)
) * 100
)
,0) AS percentage
from
cwfis_web.q1data
join
cwfis_web.q1lookup
ON cwfis_web.q1data.reasonid = cwfis_web.q1lookup.reasonid
group by
cwfis_web.q1data.reasonid;