• <bdo id='jzsN0'></bdo><ul id='jzsN0'></ul>

    <small id='jzsN0'></small><noframes id='jzsN0'>

      <legend id='jzsN0'><style id='jzsN0'><dir id='jzsN0'><q id='jzsN0'></q></dir></style></legend>
      <i id='jzsN0'><tr id='jzsN0'><dt id='jzsN0'><q id='jzsN0'><span id='jzsN0'><b id='jzsN0'><form id='jzsN0'><ins id='jzsN0'></ins><ul id='jzsN0'></ul><sub id='jzsN0'></sub></form><legend id='jzsN0'></legend><bdo id='jzsN0'><pre id='jzsN0'><center id='jzsN0'></center></pre></bdo></b><th id='jzsN0'></th></span></q></dt></tr></i><div id='jzsN0'><tfoot id='jzsN0'></tfoot><dl id='jzsN0'><fieldset id='jzsN0'></fieldset></dl></div>
    1. <tfoot id='jzsN0'></tfoot>

      1. 需要使用两个不同的 where 子句返回两组数据

        时间:2023-08-18

          <bdo id='wzqwE'></bdo><ul id='wzqwE'></ul>
          <tfoot id='wzqwE'></tfoot>
          1. <i id='wzqwE'><tr id='wzqwE'><dt id='wzqwE'><q id='wzqwE'><span id='wzqwE'><b id='wzqwE'><form id='wzqwE'><ins id='wzqwE'></ins><ul id='wzqwE'></ul><sub id='wzqwE'></sub></form><legend id='wzqwE'></legend><bdo id='wzqwE'><pre id='wzqwE'><center id='wzqwE'></center></pre></bdo></b><th id='wzqwE'></th></span></q></dt></tr></i><div id='wzqwE'><tfoot id='wzqwE'></tfoot><dl id='wzqwE'><fieldset id='wzqwE'></fieldset></dl></div>
            <legend id='wzqwE'><style id='wzqwE'><dir id='wzqwE'><q id='wzqwE'></q></dir></style></legend>

            <small id='wzqwE'></small><noframes id='wzqwE'>

                <tbody id='wzqwE'></tbody>
                  本文介绍了需要使用两个不同的 where 子句返回两组数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一张记录交易记录的表格.

                  I have a table that keeps track of transactions.

                  表格设置为:

                  transactions:
                  
                  id, account_id, budget_id, points, type
                  

                  我需要返回每个budget_id 的点总和,其中type = 'allocation' 和点总和,其中type = 'issue'

                  I need to return each budget_id's sum of points where type = 'allocation' and sum of points where type = 'issue'

                  我知道如何在一个查询中执行每个操作,但不能同时执行.

                  I know how to do each, but not both in one query.

                  预期结果集:

                  budget_id   allocated   issued
                     434       200000      100
                     242       100000      5020
                     621       45000       3940
                  

                  推荐答案

                  SELECT budget_id, 
                         SUM(IF(type = 'allocation', points, 0)) AS allocated,
                         SUM(IF(type = 'issue', points, 0)) AS issued
                  FROM transactions
                  GROUP BY budget_id
                  

                  这篇关于需要使用两个不同的 where 子句返回两组数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 my.cnf 中将 MySQL 默认字符集更改为 UTF-8? 下一篇:MySQL中的自然排序

                  相关文章

                  最新文章

                  <i id='Z8T88'><tr id='Z8T88'><dt id='Z8T88'><q id='Z8T88'><span id='Z8T88'><b id='Z8T88'><form id='Z8T88'><ins id='Z8T88'></ins><ul id='Z8T88'></ul><sub id='Z8T88'></sub></form><legend id='Z8T88'></legend><bdo id='Z8T88'><pre id='Z8T88'><center id='Z8T88'></center></pre></bdo></b><th id='Z8T88'></th></span></q></dt></tr></i><div id='Z8T88'><tfoot id='Z8T88'></tfoot><dl id='Z8T88'><fieldset id='Z8T88'></fieldset></dl></div>

                  • <bdo id='Z8T88'></bdo><ul id='Z8T88'></ul>

                    <tfoot id='Z8T88'></tfoot>
                  1. <small id='Z8T88'></small><noframes id='Z8T88'>

                      <legend id='Z8T88'><style id='Z8T88'><dir id='Z8T88'><q id='Z8T88'></q></dir></style></legend>