- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在查询时遇到了困难,但我不知道问题出在哪里。我必须根据 APPROVAL_PERIOD
计算财政年度,但 APPROVAL_PERIOD
是在 CASE WHEN
语句中计算的。
CASE WHEN DD.STATUS_CODE ='Denied' THEN
CASE WHEN CHK.MAXTRAILDATE BETWEEN '2015-05-22 00:00:00.0000000' AND '2015-05-31 00:00:00.0000000' THEN '201506'
ELSE
(CONVERT(CHAR(4),CHK.MAXTRAILDATE, 120) +''+SUBSTRING(CONVERT(nvarchar(6),CHK.MAXTRAILDATE, 112),5,2))
END
ELSE
CASE WHEN DD.APPROVAL_DATE BETWEEN '2015-05-22 00:00:00.0000000' AND '2015-05-31 00:00:00.0000000' THEN '201506'
ELSE
(CONVERT(CHAR(4),DD.APPROVAL_DATE, 120) +''+SUBSTRING(CONVERT(nvarchar(6),DD.APPROVAL_DATE, 112),5,2))
END
END AS APPROVAL_PERIOD,
CASE
WHEN APPROVAL_DATE between '2004-10-01 00:00:00.000' and '2005-09-30 23:59:00.000' THEN 'FY05'
WHEN APPROVAL_DATE between '2005-10-01 00:00:00.000' and '2006-09-30 23:59:00.000' THEN 'FY06'
WHEN APPROVAL_DATE between '2006-10-01 00:00:00.000' and '2007-09-30 23:59:00.000' THEN 'FY07'
WHEN APPROVAL_DATE between '2007-10-01 00:00:00.000' and '2008-09-28 23:59:00.000' THEN 'FY08'
WHEN APPROVAL_DATE between '2008-09-29 00:00:00.000' and '2009-09-30 23:59:00.000' THEN 'FY09'
WHEN APPROVAL_DATE between '2009-10-01 00:00:00.000' and '2010-09-30 23:59:59.000' THEN 'FY10'
WHEN APPROVAL_DATE between '2010-10-01 00:00:00.000' and '2011-09-30 23:59:59.000' THEN 'FY11'
WHEN APPROVAL_DATE between '2011-10-01 00:00:00.000' and '2012-09-30 23:59:59.000' THEN 'FY12'
WHEN APPROVAL_DATE between '2012-10-01 00:00:00.000' and '2013-09-30 23:59:59.000' THEN 'FY13'
WHEN APPROVAL_DATE between '2013-10-01 00:00:00.000' and '2014-09-30 23:59:59.000' THEN 'FY14'
WHEN APPROVAL_DATE between '2014-10-01 00:00:00.000' and '2015-09-30 23:59:59.000' THEN 'FY15'
WHEN APPROVAL_DATE between '2015-10-01 00:00:00.000' and '2016-09-30 23:59:59.000' THEN 'FY16'
WHEN APPROVAL_DATE between '2016-10-01 00:00:00.000' and '2017-09-30 23:59:59.000' THEN 'FY17'
WHEN APPROVAL_DATE between '2017-10-01 00:00:00.000' and '2018-09-30 23:59:59.000' THEN 'FY18'
WHEN APPROVAL_DATE between '2018-10-01 00:00:00.000' and '2019-09-30 23:59:59.000' THEN 'FY19'
WHEN APPROVAL_DATE between '2019-10-01 00:00:00.000' and '2020-09-30 23:59:59.000' THEN 'FY20'
WHEN APPROVAL_DATE between '2020-10-01 00:00:00.000' and '2021-09-30 23:59:59.000' THEN 'FY21'
WHEN APPROVAL_DATE between '2021-10-01 00:00:00.000' and '2022-09-30 23:59:59.000' THEN 'FY22'
ELSE ' '
END AS FY
FROM table
我根据APPROVAL DATE
计算了财政年度,但我需要根据APPROVAL_PERIOD
来计算。有什么办法可以做到吗?
最佳答案
只是一个如何在查询中使用动态 mysql 变量的示例:
http://sqlfiddle.com/#!9/9eecb7d/24641
SELECT
case when 1 then @var := 'one' else @var := 'two' end field1,
case when @var ='one' then 'two' else 'three' end field2
更新在你的情况下,它会是这样的
CASE WHEN DD.STATUS_CODE ='Denied' THEN
CASE WHEN CHK.MAXTRAILDATE BETWEEN '2015-05-22 00:00:00.0000000' AND '2015-05-31 00:00:00.0000000' THEN @var := '201506'
ELSE
@var := (CONVERT(CHAR(4),CHK.MAXTRAILDATE, 120) +''+SUBSTRING(CONVERT(nvarchar(6),CHK.MAXTRAILDATE, 112),5,2))
END
ELSE
CASE WHEN DD.APPROVAL_DATE BETWEEN '2015-05-22 00:00:00.0000000' AND '2015-05-31 00:00:00.0000000' THEN @var := '201506'
ELSE
@var := (CONVERT(CHAR(4),DD.APPROVAL_DATE, 120) +''+SUBSTRING(CONVERT(nvarchar(6),DD.APPROVAL_DATE, 112),5,2))
END
END AS APPROVAL_PERIOD,
CASE
WHEN @var between '2004-10-01 00:00:00.000' and '2005-09-30 23:59:00.000' THEN 'FY05'
WHEN @var between '2005-10-01 00:00:00.000' and '2006-09-30 23:59:00.000' THEN 'FY06'
WHEN @var between '2006-10-01 00:00:00.000' and '2007-09-30 23:59:00.000' THEN 'FY07'
WHEN @var between '2007-10-01 00:00:00.000' and '2008-09-28 23:59:00.000' THEN 'FY08'
WHEN @var between '2008-09-29 00:00:00.000' and '2009-09-30 23:59:00.000' THEN 'FY09'
WHEN @var between '2009-10-01 00:00:00.000' and '2010-09-30 23:59:59.000' THEN 'FY10'
WHEN @var between '2010-10-01 00:00:00.000' and '2011-09-30 23:59:59.000' THEN 'FY11'
WHEN @var between '2011-10-01 00:00:00.000' and '2012-09-30 23:59:59.000' THEN 'FY12'
WHEN @var between '2012-10-01 00:00:00.000' and '2013-09-30 23:59:59.000' THEN 'FY13'
WHEN @var between '2013-10-01 00:00:00.000' and '2014-09-30 23:59:59.000' THEN 'FY14'
WHEN @var between '2014-10-01 00:00:00.000' and '2015-09-30 23:59:59.000' THEN 'FY15'
WHEN @var between '2015-10-01 00:00:00.000' and '2016-09-30 23:59:59.000' THEN 'FY16'
WHEN @var between '2016-10-01 00:00:00.000' and '2017-09-30 23:59:59.000' THEN 'FY17'
WHEN @var between '2017-10-01 00:00:00.000' and '2018-09-30 23:59:59.000' THEN 'FY18'
WHEN @var between '2018-10-01 00:00:00.000' and '2019-09-30 23:59:59.000' THEN 'FY19'
WHEN @var between '2019-10-01 00:00:00.000' and '2020-09-30 23:59:59.000' THEN 'FY20'
WHEN @var between '2020-10-01 00:00:00.000' and '2021-09-30 23:59:59.000' THEN 'FY21'
WHEN @var between '2021-10-01 00:00:00.000' and '2022-09-30 23:59:59.000' THEN 'FY22'
ELSE ' '
END AS FY
FROM table
如有任何疑问,非常欢迎您
关于mysql - 从案例陈述中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33017158/
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
显然,我实际上是想创建一个数组,在多次试验 (5000) 中随机分配生日。然后假设每次有 2 - 50 人至少有 2 个生日时,将结果除以 5,000 以获得近似概率。我相信我的循环搞砸了,希望得到一
PYTHON:试图计算摆在不同行星上摆动所需的时间,我对此非常陌生,因此可能有一个简单的解决方案: def main(): print('Period of a pendulum')
在我的 MySQL 表中,有一行标记为“state”。有 3 个可能的值。我如何利用 PHP 将“Unbanned”回显为状态中的“0”?将“禁止”与“1”相对应,将“临时禁止”与“3”相对应? 我如
我的宏代码中有一个 If 公式,但它似乎没有以正确的方式工作。 下面的代码计算 rCell.Offset 并始终将其应用为 True,我有一些示例,其中它等于 112、113、118 等,并且它正在将
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: Why do you have to put a 1; at the end of a Perl 5 module?
网上查了一下parent::init();的意思.我所能找到的只是 init() 是初始化一些设置,这些设置希望在每次应用程序运行时出现。谁能准确解释 parent::init() 的含义,比如这两个
这个问题已经有答案了: What does "%.*s" mean in printf? (4 个回答) 已关闭 3 年前。 我试图理解 printf() 但我只熟悉 C++ cout= 0; r--
我正在开发一个试图通过 tsv infile 将数据插入 mysql 数据库的 java 项目。运行该程序时出现以下错误: Exception in thread "main" java.sql.SQ
好的,我正在开发一个新的应用程序,只要我使用相对 View ,一切都运行良好。但是,我想要一个选项卡式布局,所以我将我拥有的内容(到目前为止还不多,因为我刚刚从数据库中读取它并且设置正常)切换到选项卡
我在另一个问题中看到了这个提示,想知道是否有人可以向我解释这究竟是如何工作的? try { return x; } finally { x = null; } 我的意思是,finally 子句是否真的
这个问题已经有答案了: Is it better to wrap code into an 'IF' statement, or is it better to 'short circuit' the
我是一名优秀的程序员,十分优秀!