首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对子查询返回多行时的值进行求和。(我的用例是2行)

对子查询返回多行时的值进行求和。(我的用例是2行)
EN

Stack Overflow用户
提问于 2017-10-28 17:21:35
回答 1查看 84关注 0票数 0

通过查询,我有多行数据。如何对这些行进行分组,以求出其中一些行的值,并留下其余行的值。

代码语言:javascript
复制
set total_fees1 = (select (f.total_Fees2) from fee_Collection f where f.student_Id =minstudent_Id);
            set total_fees2 = (select (f.total_Fees3) from fee_Collection f where f.student_Id =minstudent_Id);
            set paid_amount1 = (select (f.paid_amount2) from fee_Collection f where f.student_Id =minstudent_Id);
            set paid_amount2 = (select (f.paid_amount3) from fee_Collection f where f.student_Id =minstudent_Id);

上述查询在某些情况下会返回2行。现在,我必须在获得超过1行的情况下添加paid_amount值,并取total_fees字段的第一行的值。

EN

回答 1

Stack Overflow用户

发布于 2017-10-29 06:39:04

这将是:

代码语言:javascript
复制
set total_fees1 = (select (f.total_Fees2) from fee_Collection f where f.student_Id =minstudent_Id LIMIT 1);
        set total_fees2 = (select (f.total_Fees3) from fee_Collection f where f.student_Id =minstudent_Id LIMIT 1);
        set paid_amount1 = (select SUM(f.paid_amount2) from fee_Collection f where f.student_Id =minstudent_Id);
        set paid_amount2 = (select SUM(f.paid_amount3) from fee_Collection f where f.student_Id =minstudent_Id);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46988146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档