我正在执行此查询:
SELECT
voterfile_county.Name,
voterfile_precienct.PREC_ID,
voterfile_precienct.Name,
COUNT((SELECT voterfile_voter.ID
FROM voterfile_voter
JOIN voterfile_household
WHERE voterfile_voter.House_ID = voterfile_household.ID
AND voterfile_household.Precnum = voterfile_precienct.PREC_ID)) AS Voters
FROM voterfile_precienct JOIN voterfile_county
WHERE voterfile_precienct.County_ID = voterfile_County.ID;
我试图让它返回这样的东西:
County_Name Prec_ID Prec_Name Voters(Count of # of voters in that precienct)
但是,我收到错误:
#1242 – Subquery returns more than 1 row.
我已经尝试将COUNT语句放在子查询中,但是我得到一个无效的语法错误。