本文介绍了sql查询计算agroup计数的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

fields id ,party,votes

fields id ,party,votes

我的查询像这样得到 o/p

my query getting o/p like this

 partyname    bjp      aap         congress

  votes        1        2              2

但我也需要总票数.以下是我的预期输出.

  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";

推荐答案

看看这个

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

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

只是一个想法如何获得 SUM

Just an idea how you can get the SUM

这篇关于sql查询计算agroup计数的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 05:12