在JOIN查询中放置条件的位置?

时间:2014-10-11 12:46:57

标签: mysql sql

下面是我显示分区的查询,但我需要选择其分区= nagpur

的所有数据

我的意思是,我想在我的查询中放置条件。请建议我如何实现以下查询中的条件。

SELECT RES.PARTYNAME, RES.DISTRICT, COUNT(RES.CONSTITUENCY) AS VOTESCOUNT 
FROM voter_count RES 
JOIN 
    (SELECT CONSTITUENCY, MAX(VOTES) AS VOTES 
    FROM voter_count
    GROUP BY CONSTITUENCY) MAXS 
USING (VOTES, CONSTITUENCY) 
GROUP BY PARTYNAME,DISTRICT

1 个答案:

答案 0 :(得分:0)

尝试以下查询

SELECT RES.PARTYNAME, RES.DISTRICT, COUNT( RES.CONSTITUENCY ) AS VOTESCOUNT 
FROM voter_count RES 
JOIN 
  (SELECT CONSTITUENCY, MAX(VOTES) AS VOTES 
   FROM voter_count
   GROUP BY CONSTITUENCY) MAXS 
USING (VOTES, CONSTITUENCY)
WHERE RES.DISTRICT = 'nagpur'  
GROUP BY PARTYNAME, DISTRICT