raj malhotra
raj malhotra

Reputation: 23

sql query to calculate sum of agroup counts

fields id ,party,votes

my query getting o/p like this

 partyname    bjp      aap         congress   

  votes        1        2              2    

but i also need sum of votes. below is my expected output.

  BJP         aap           congress       total

   1             2            2             5

SELECT RES.PARTYNAME, 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 LIMIT 0 , 1000";

Upvotes: 0

Views: 52

Answers (2)

Jayakarthik Appasamy
Jayakarthik Appasamy

Reputation: 129

According to your table,

SELECT SUM(partyname) AS total_parties, SUM(votes) AS total_votes FROM table_name;

is this what you want?? Your question is not clear & query is irrelavant to description...

Upvotes: 0

Dese Dere
Dese Dere

Reputation: 13

Take a look at this

SELECT SUM(something) AS something, SUM(else) AS else FROM stuff

Just an idea how you can get the SUM

Upvotes: 1

Related Questions