MySQL subquery returns more than one row

前端 未结 4 2099
粉色の甜心
粉色の甜心 2020-12-01 16:22

I am executing this query:

SELECT
    voterfile_county.Name,
    voterfile_precienct.PREC_ID,
    voterfile_precienct.Name,
    COUNT((SELECT voterfile_vote         


        
4条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 16:51

    You can try it without the subquery, with a simple group by:

    SELECT voterfile_county.Name, 
      voterfile_precienct.PREC_ID, 
      voterfile_precienct.Name, 
      count(voterfile_voter.ID)
    FROM voterfile_county
    JOIN voterfile_precienct 
      ON voterfile_precienct.County_ID = voterfile_County.ID
    JOIN voterfile_household 
      ON voterfile_household.Precnum = voterfile_precienct.PREC_ID
    JOIN voterfile_voter 
      ON voterfile_voter.House_ID = voterfile_household.ID 
    GROUP BY voterfile_county.Name, 
      voterfile_precienct.PREC_ID, 
      voterfile_precienct.Name
    

    When you use GROUP BY, any column that you are not grouping on must have an aggregate clause (f.e. SUM or COUNT.) So in this case you have to group on county name, precienct.id and precient.name.

提交回复
热议问题