2014-10-11 133 views
0

以下是我的查詢顯示分區,但我需要選擇所有數據的分區= nagpur哪裏把條件放入JOIN查詢?

我的意思是,我想把條件放在我的查詢中。請建議我如何在下面的查詢中實現條件。

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 
+0

後'from' :-)或''組by'後having'。 – Rufinus 2014-10-11 12:49:35

回答

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 
+0

@ashish:有幫助嗎? – 2014-10-11 13:06:00

+0

好的感謝它的工作很好... – ashish 2014-10-11 13:10:24