作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有以下格式的数据:
date
(mm/dd/yyyy), desc
(详细说明), category
(a,b,c), tran_type
(借方、贷方),花费金额
(金额)。
我想获取以下格式的数据:
category || tran_type || Jan_total || feb_total || mar_total
A || debit || $101 || $201 || $302
A || credit || $500 || $600 || $200
最佳答案
这个查询应该给你所需的结果。
SELECT category
,tran_type
,SUM(IF(month(date) = 1,ABS(amount),0)) as jan_total
,SUM(IF(month(date) = 2,ABS(amount),0)) as feb_total
,SUM(IF(month(date) = 3,ABS(amount),0)) as mar_total
,SUM(IF(month(date) = 4,ABS(amount),0)) as apr_total
,SUM(IF(month(date) = 5,ABS(amount),0)) as may_total
,SUM(IF(month(date) = 6,ABS(amount),0)) as jun_total
,SUM(IF(month(date) = 7,ABS(amount),0)) as jul_total
,SUM(IF(month(date) = 8,ABS(amount),0)) as aug_total
,SUM(IF(month(date) = 9,ABS(amount),0)) as sep_total
,SUM(IF(month(date) = 10,ABS(amount),0)) as okt_total
,SUM(IF(month(date) = 11,ABS(amount),0)) as nov_total
,SUM(IF(month(date) = 12,ABS(amount),0)) as dec_total
FROM transactions
WHERE YEAR(date) = '2011'
GROUP BY category, tran_type
如果您不想遇到麻烦,请不要忘记过滤年份。
关于mySQL查询列中的总金额(月),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5926835/
我正在尝试在 excel 中创建一个公式(而不是数据透视表)来执行以下操作: 检查在给定月份(例如在本例中为一月)内支付了哪些款项,然后合计 A 类下的金额。这是一个数据示例: | Date
我正在使用 Rails 和 MySql,目前,我的数据在 View 中显示如下: Customer A, 5 Customer B, 3 Customer C, 2 Customer A, 2 Cus
如果我有以下代码,我如何计算最终支付的价格 $Total : {foreach from=$items key=k item=item} {$i
Javascript 代码: $(document).on('click', '#google_analytics', function() { if ($("#google_analytic
我是一名优秀的程序员,十分优秀!