当前位置: 首页 > 知识库问答 >
问题:

按联邦财政年度重新排序月份

戴凯歌
2023-03-14

当运行下面的查询时,我试图找到一种方法来按联邦财政年度显示返回的月份,而不是正常的顺序值。

(我想按以下顺序显示月份:10月、11月、12月、1月、2月、3月、4月、5月、6月、7月、8月、9月,而不是1月至12月)谢谢

select wrkgrp,
    sum (case when extract(month from reportdate) = 1 then 1 else 0 end) as January,
    sum (case when extract(month from reportdate) = 2 then 1 else 0 end) as February,
    sum (case when extract(month from reportdate) = 3 then 1 else 0 end) as March,
    sum (case when extract(month from reportdate) = 4 then 1 else 0 end) as April,
    sum (case when extract(month from reportdate) = 5 then 1 else 0 end) as May,
    sum (case when extract(month from reportdate) = 6 then 1 else 0 end) as June,
    sum (case when extract(month from reportdate) = 7 then 1 else 0 end) as July,
    sum (case when extract(month from reportdate) = 8 then 1 else 0 end) as August,
    sum (case when extract(month from reportdate) = 9 then 1 else 0 end) as September,
    sum (case when extract(month from reportdate) = 10 then 1 else 0 end) as October,
    sum (case when extract(month from reportdate) = 11 then 1 else 0 end) as November,
    sum (case when extract(month from reportdate) = 12 then 1 else 0 end) as December,
from workorder
where reportdate between to_date ('2014-10-01 00:00:00', 'yyyy/mm/dd hh24:mi:ss')
and   to_date ('2015-09-30 00:00:00', 'yyyy/mm/dd hh24:mi:ss')
and   wrkgrp = 'PublicWorks'
group by 'wrkgrp;'

共有1个答案

闽康安
2023-03-14

字段将按select语句中列出的顺序(水平)显示在结果中。使用Oct首先列出的语句结构,如下所示:

select wrkgrp,
sum (case when extract(month from reportdate) = 10 then 1 else 0 end) as October,
sum (case when extract(month from reportdate) = 11 then 1 else 0 end) as November,
sum (case when extract(month from reportdate) = 12 then 1 else 0 end) as December,
sum (case when extract(month from reportdate) = 1 then 1 else 0 end) as January,
sum (case when extract(month from reportdate) = 2 then 1 else 0 end) as February,
sum (case when extract(month from reportdate) = 3 then 1 else 0 end) as March,
sum (case when extract(month from reportdate) = 4 then 1 else 0 end) as April,
sum (case when extract(month from reportdate) = 5 then 1 else 0 end) as May,
sum (case when extract(month from reportdate) = 6 then 1 else 0 end) as June,
sum (case when extract(month from reportdate) = 7 then 1 else 0 end) as July,
sum (case when extract(month from reportdate) = 8 then 1 else 0 end) as August,
sum (case when extract(month from reportdate) = 9 then 1 else 0 end) as September
from workorder
where reportdate between to_date ('2014-10-01 00:00:00', 'yyyy/mm/dd hh24:mi:ss') ad to_date ('2015-09-30 00:00:00', 'yyyy/mm/dd hh24:mi:ss') and
wrkgrp = 'PublicWorks'
group by 'wrkgrp;'
 类似资料:
  • 有没有办法根据日期范围找出年份和季度? 我们考虑将11月作为财政年度的开始日期,将10月作为财政年度的结束日期。 前一年的11月到下一年的10月被认为是一个财政年度。 2014年11月1日-2015年10月31日- 10月31日之后的任何记录都将进入下一个财政年度。 我们还需要找到如下宿舍: 第1季度=11月、12月 - 但它被认为是第一季度。 --代码-- 函数getQuarter(){var

  • 问题内容: 我正在尝试构造一个查询,该查询将映射两列,一列是表中的日期,第二列是别名,以显示日期所属的季度和财务年度。 不幸的是,我没有足够的SQL知识来知道从哪里开始。我知道,我会用的组合做到这一点,并却没有,我已经把已接近工作。 更复杂的是,澳大利亚的财政年度从7月1日至6月30日开始,因此2012财政年度的第一季度将从2012年7月1日开始。 我可以不用声明就可以做到这一点,但是我宁愿在声明

  • 我习惯于使用PostgreSQL,我知道Postgre中的分区,分组,排名功能。我现在使用的是MySQL5.2,我的表如下所示: 我基本上想要的是每个ID的频率最低年-月,即基本上每个ID的最高值,因为顺序总是年-月上升。 谁能给我一些建议。我非常感谢任何提示和建议。

  • 我在使用IMDb数据集时遇到了一个问题,我似乎无法解决这个问题。这个问题要求只放映1995年制作的电影。问题是,这一年是与每一个电影标题一起列出的,即:“玩具总动员(1995)”。你怎么能从一串文本中刮出年份? 问题是:

  • Kubernetes v1.9声称单集群最多可支持5000个节点和15万个Pod,我相信很少有公司会部署如此庞大的一个单集群,总有很多情况下因为各种各样的原因我们可能会部署多个集群,但是有时候有想将他们统一起来管理,这时候就需要用到集群联邦(Federation)。 为什么要使用 federation Federation 使管理多个集群变得简单。它通过提供两个主要构建模块来实现: 跨集群同步资源

  • 问题内容: 我有一个当前订购的月份名称数组,例如(“ April”,“ August”,“ February”)等。我想对该列表进行重新排序,使其处于正常的月份顺序,例如(“ January”,“二月三月”) 该数组是从SHOW TABLES sql查询中填充的,不幸的是,SHOW TABLES没有ORDER BY参数,因此我认为最好的选择是将它们添加到数组中并重新排序该数组以获取所需的内容。 问