社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  DATABASE

如何计算MySQL中的最大值?

SRV • 5 年前 • 1451 次点击  
    SELECT 
       DISTINCT(ecode_id)
      ,MAX(eligible_allowance)AS monthlyBudgetAmt
      ,approval_date
    FROM vefm_dailybudget
    WHERE
        division=1 AND region=1
        AND unit=1 AND common_status IN('Finance - II Approved','Cash Disbursement')
        AND eligible_allowance != 0
        AND approval_date BETWEEN ' 2019-02-01'
        AND '2019-02-28' AND budget_type='monthly'
    GROUP BY ecode_id ORDER BY ecode_id

下面是我从上面得到的值,总共91行。我不想显示91行,而是要显示符合条件的津贴的总值。有人能帮忙吗

Ecode ID Eligible Allowance Approval Date
E2404   12000   2019-02-14
E2660   9000    2019-02-19
E2694   10500   2019-02-14
E2739   7500    2019-02-14
E2911   7500    2019-02-14
E2912   7500    2019-02-14
E2929   7500    2019-02-14
E2967   7500    2019-02-14
E3013   7500    2019-02-14
E3100   6000    2019-02-14
E3168   7500    2019-02-14
E3199   7500    2019-02-14
E3225   7500    2019-02-27
E3301   6000    2019-02-14
E3441   6000    2019-02-14
E3451   6000    2019-02-14
E3548   6000    2019-02-22
E3581   6000    2019-02-14
E3602   6000    2019-02-22
E3647   7500    2019-02-02
E3650   6000    2019-02-14
E3684   6000    2019-02-14
E3698   7500    2019-02-14
E3701   6000    2019-02-27
E3703   7500    2019-02-14

我需要以上查询的和值是516000

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/53358
 
1451 次点击  
文章 [ 1 ]  |  最新文章 5 年前
forpas
Reply   •   1 楼
forpas    6 年前

你需要总结一下 monthlyBudgetAmt 您的问题:

SELECT SUM(t.monthlyBudgetAmt) AS total FROM (
    SELECT 
      MAX(eligible_allowance) AS monthlyBudgetAmt
    FROM vefm_dailybudget
    WHERE
        division=1 AND region=1
        AND unit=1 AND common_status IN('Finance - II Approved','Cash Disbursement')
        AND eligible_allowance != 0
        AND approval_date BETWEEN '2019-02-01'
        AND '2019-02-28' AND budget_type='monthly'
    GROUP BY ecode_id
) t