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

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

      <tfoot id='SUncW'></tfoot>

      <legend id='SUncW'><style id='SUncW'><dir id='SUncW'><q id='SUncW'></q></dir></style></legend>
    1. MySQL 过去 12 个月的每月销售,包括没有销售的月份

      时间:2023-06-03

      <legend id='vuMfD'><style id='vuMfD'><dir id='vuMfD'><q id='vuMfD'></q></dir></style></legend>
        <tbody id='vuMfD'></tbody>
        • <bdo id='vuMfD'></bdo><ul id='vuMfD'></ul>

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

            1. <tfoot id='vuMfD'></tfoot>
            2. <i id='vuMfD'><tr id='vuMfD'><dt id='vuMfD'><q id='vuMfD'><span id='vuMfD'><b id='vuMfD'><form id='vuMfD'><ins id='vuMfD'></ins><ul id='vuMfD'></ul><sub id='vuMfD'></sub></form><legend id='vuMfD'></legend><bdo id='vuMfD'><pre id='vuMfD'><center id='vuMfD'></center></pre></bdo></b><th id='vuMfD'></th></span></q></dt></tr></i><div id='vuMfD'><tfoot id='vuMfD'></tfoot><dl id='vuMfD'><fieldset id='vuMfD'></fieldset></dl></div>
                本文介绍了MySQL 过去 12 个月的每月销售,包括没有销售的月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                SELECT DATE_FORMAT(date, "%b") AS month, SUM(total_price) as total
                FROM cart
                WHERE date <= NOW()
                and date >= Date_add(Now(),interval - 12 month)
                GROUP BY DATE_FORMAT(date, "%m-%Y")
                

                此查询仅显示现有月份的结果.我需要所有 12 个月的销售额.

                This query displaying result for only existing month. I need all 12 months sales.

                输出:

                "month" "total"  
                --------------  
                "Jun"   "22"
                "Aug"   "30"
                "Oct"   "19"
                "Nov"   "123"
                "Dec"   "410"
                

                所需输出:

                "month" "total"  
                --------------
                "Jan"   "0"
                "Feb"   "0"
                "Mar"   "0"
                "Apr"   "0"
                "May"   "0"
                "Jun"   "22"
                "Jul"   "0"
                "Aug"   "30"
                "Sep"   "0"
                "Oct"   "19"
                "Nov"   "123"
                "Dec"   "410"
                

                推荐答案

                感谢@pankaj 的提示,我在这里通过这个查询解决了...

                Thanks for @pankaj hint, Here i resolved it via this query...

                SELECT 
                    SUM(IF(month = 'Jan', total, 0)) AS 'Jan',
                    SUM(IF(month = 'Feb', total, 0)) AS 'Feb',
                    SUM(IF(month = 'Mar', total, 0)) AS 'Mar',
                    SUM(IF(month = 'Apr', total, 0)) AS 'Apr',
                    SUM(IF(month = 'May', total, 0)) AS 'May',
                    SUM(IF(month = 'Jun', total, 0)) AS 'Jun',
                    SUM(IF(month = 'Jul', total, 0)) AS 'Jul',
                    SUM(IF(month = 'Aug', total, 0)) AS 'Aug',
                    SUM(IF(month = 'Sep', total, 0)) AS 'Sep',
                    SUM(IF(month = 'Oct', total, 0)) AS 'Oct',
                    SUM(IF(month = 'Nov', total, 0)) AS 'Nov',
                    SUM(IF(month = 'Dec', total, 0)) AS 'Dec',
                    SUM(total) AS total_yearly
                    FROM (
                SELECT DATE_FORMAT(date, "%b") AS month, SUM(total_price) as total
                FROM cart
                WHERE date <= NOW() and date >= Date_add(Now(),interval - 12 month)
                GROUP BY DATE_FORMAT(date, "%m-%Y")) as sub
                

                这篇关于MySQL 过去 12 个月的每月销售,包括没有销售的月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 MySQL 5.6 中重置 ROOT 密码 下一篇:mySQL 返回每个类别的前 5 个

                相关文章

              • <legend id='W2kSL'><style id='W2kSL'><dir id='W2kSL'><q id='W2kSL'></q></dir></style></legend>

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

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