- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要按月份、县和计划生成支出 list 和申请数量。到目前为止,我已经能够获得支出 list ,但我无法获得每月申请数量的 list 。这是我到目前为止的查询,但申请数量不正确。
select
servicecounty AS County,
program,
sum(case when month(entrydate) = 1 and year(entrydate) = 2014 then totalpaymenttotal else 0 end) as January,
sum(case when month(entrydate) = 2 and year(entrydate) = 2014 then totalpaymenttotal else 0 end) as February,
sum(case when month(entrydate) = 3 and year(entrydate) = 2014 then totalpaymenttotal else 0 end) as March,
sum(case when month(entrydate) = 4 and year(entrydate) = 2014 then totalpaymenttotal else 0 end) as April,
sum(case when month(entrydate) = 5 and year(entrydate) = 2014 then totalpaymenttotal else 0 end) as May,
sum(case when month(entrydate) = 6 and year(entrydate) = 2014 then totalpaymenttotal else 0 end) as June,
sum(case when month(entrydate) = 7 and year(entrydate) = 2014 then totalpaymenttotal else 0 end) as July,
sum(case when month(entrydate) = 8 and year(entrydate) = 2014 then totalpaymenttotal else 0 end) as August,
sum(case when month(entrydate) = 9 and year(entrydate) = 2014 then totalpaymenttotal else 0 end) as September,
sum(case when month(entrydate) = 10 and year(entrydate) = 2014 then totalpaymenttotal else 0 end) as October,
sum(case when month(entrydate) = 11 and year(entrydate) = 2014 then totalpaymenttotal else 0 end) as November,
sum(case when month(entrydate) = 12 and year(entrydate) = 2014 then totalpaymenttotal else 0 end) as December,
sum(case when month(entrydate) = 1 and year(entrydate) = 2015 then totalpaymenttotal else 0 end) as [January 15],
sum(case when month(entrydate) = 2 and year(entrydate) = 2015 then totalpaymenttotal else 0 end) as [February 15],
sum(case when month(entrydate) = 3 and year(entrydate) = 2015 then totalpaymenttotal else 0 end) as [March 15],
sum(case when month(entrydate) = 4 and year(entrydate) = 2015 then totalpaymenttotal else 0 end) as [April 15]
from Sheet$
group by servicecounty, program
UNION ALL
select
servicecounty AS County,
program,
COUNT(case when month(entrydate) = 1 and year(entrydate) = 2014 then ApplicationID else 0 end) as January,
count(case when month(entrydate) = 2 and year(entrydate) = 2014 then ApplicationID else 0 end) as February,
count(case when month(entrydate) = 3 and year(entrydate) = 2014 then ApplicationID else 0 end) as March,
count(case when month(entrydate) = 4 and year(entrydate) = 2014 then ApplicationID else 0 end) as April,
count(case when month(entrydate) = 5 and year(entrydate) = 2014 then ApplicationID else 0 end) as May,
count(case when month(entrydate) = 6 and year(entrydate) = 2014 then ApplicationID else 0 end) as June,
count(case when month(entrydate) = 7 and year(entrydate) = 2014 then ApplicationID else 0 end) as July,
count(case when month(entrydate) = 8 and year(entrydate) = 2014 then ApplicationID else 0 end) as August,
count(case when month(entrydate) = 9 and year(entrydate) = 2014 then ApplicationID else 0 end) as September,
count(case when month(entrydate) = 10 and year(entrydate) = 2014 then ApplicationID else 0 end) as October,
count(case when month(entrydate) = 11 and year(entrydate) = 2014 then ApplicationID else 0 end) as November,
count(case when month(entrydate) = 12 and year(entrydate) = 2014 then ApplicationID else 0 end) as December,
Count(case when month(entrydate) = 1 and year(entrydate) = 2015 then ApplicationID else 0 end) as [January 15],
Count(case when month(entrydate) = 2 and year(entrydate) = 2015 then ApplicationID else 0 end) as [February 15],
Count(case when month(entrydate) = 3 and year(entrydate) = 2015 then ApplicationID else 0 end) as [March 15],
Count(case when month(entrydate) = 4 and year(entrydate) = 2015 then ApplicationID else 0 end) as [April 15]
from Sheet$
group by servicecounty, program
ORDER BY program
报告应该是这样的:
按月、计划和县分列的支出: http://i.stack.imgur.com/yJ26A.jpg
按月、计划和县划分的应用程序数量: http://i.stack.imgur.com/7Aqkk.png
该表包含以下字段:ServiceCounty、TotalPaymentTotal、Program、ApplicationID、EntryDate
在此先感谢您的帮助。
最佳答案
您在第二个子查询中的计数都返回相同的值。请记住,count()
计算非 NULL 值的数量。而且,0
不为空。
三种解决方案:
count()
更改为 sum()
并将 then
更改为 then 1
。else
。else 0
更改为 else NULL
。这些是我个人喜好的顺序。
关于mysql - SQL 查询 : Number of applications by month, 县和计划,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33310812/
我有国家、地区、县、城镇数据,目前我正在决定 2 种模式设计(如果有更好的,请告诉我)。 我首先想到的 国家 身份证 姓名 地区 身份证 国家/地区 姓名 县 身份证 地区编号 姓名 城镇 身份证 县
我有两个数据集 df_state 和 df_city。 df_state 有一个数值的总和(net_value_x)。 df_city 在城市级别对数值 (value_x) 进行了分割 这只是德克萨斯
我有一个美国邮政编码及其对应的州、市和县的数据库。它以平面文件的形式提供,我正在尝试规范化数据并准确找出哪些实体依赖于哪些实体。 我遇到的一个问题是,有些城市似乎存在于多个县。我的印象是,在美国,存在
他们使用什么流程或 API 在他们的网站上提供此功能?如果它太复杂而无法解释,请您朝着正确的方向努力,以便也能够提供此功能。谢谢。 最佳答案 研究地理编码、地理标记和 GIS http://en.wi
R新手在这里。 如果我第一次使用 map('state') , 那么我如何使用 map('county', ylim=..., xlim=...)但像这样抵消它: 现在,我正在使用 imagemagi
以下查询适用于一种分类法 SELECT * FROM bb_posts AS p LEFT JOIN bb_term_relationships AS r ON (p.ID = r.object_id
利用 Mike Bostocks 美国各县区 block :https://bl.ocks.org/mbostock/4122298 。 目标是创建一个鼠标移动函数,在事件期间鼠标移动将突出显示所有选
在我的 MVC 应用程序中,我想显示用户访问网站的国家/地区、地区和城市。我怎样才能获取它们? 最佳答案 有几种方法。一种是要求用户与远程服务器共享他的位置。 https://developer.mo
我是一名优秀的程序员,十分优秀!