- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
下面是我正在尝试操作的示例数据。
+----------------+------------------+---------+------+--------------+-------------+--+--+
| ACCOUNT_NUMBER | TRANSACTION_DATE | bal | Row# | RunningTotal | status | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 31/03/2015 | 82.61 | 4 | 82.61 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 31/03/2015 | 85.25 | 5 | 167.86 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 31/03/2015 | 93.61 | 6 | 261.47 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 30/04/2015 | 78.95 | 7 | 340.42 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 22/05/2015 | -62.04 | 8 | 278.38 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 31/05/2015 | 98.95 | 9 | 377.33 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 30/06/2015 | 79.5 | 10 | 456.83 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 15/07/2015 | -345.76 | 11 | 111.07 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 12/05/2016 | -111.07 | 12 | 0 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 31/03/2015 | 2.5 | 13 | 2.5 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 31/03/2015 | 2.5 | 14 | 5 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 31/03/2015 | 2.5 | 15 | 7.5 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 30/04/2015 | 2.5 | 16 | 10 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 31/05/2015 | 2.5 | 17 | 12.5 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 30/06/2015 | 0.67 | 18 | 13.17 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 30/07/2015 | -0.81 | 19 | 12.36 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 31/05/2018 | 5.08 | 20 | 17.44 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 30/11/2018 | 1.02 | 21 | 18.46 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 31/05/2019 | 1.48 | 22 | 19.94 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 31/03/2015 | 8.38 | 23 | 8.38 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 31/03/2015 | 10.65 | 24 | 19.03 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 31/03/2015 | 25.07 | 25 | 44.1 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 30/04/2015 | 12.21 | 26 | 56.31 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 30/04/2015 | -20 | 27 | 36.31 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 20/05/2015 | -36.31 | 28 | 0 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 31/05/2015 | -3.69 | 29 | -3.69 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 31/05/2015 | 13.17 | 30 | 9.48 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 30/06/2015 | 9 | 31 | 18.48 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 25/07/2015 | -18.48 | 32 | 0 | CLEARED
下面是用于应用发票状态的脚本。本质上,我希望能够确定某个帐户是否已取消其所有发票。我有两个条件:
select *,
(CASE WHEN sum(bal) OVER (PARTITION BY ACCOUNT_NUMBER ) = 0 THEN 'CLEARED'
WHEN sum(bal) OVER (PARTITION BY ACCOUNT_NUMBER order by Row#,TRANSACTION_DATE ) = 0 THEN 'CLEARED'
else 'NOT_CLEARED'
end) as status
from #running_totals
order by Row#, TRANSACTION_DATE
有人可以帮助我如何应用它吗预期结果
+----------------+------------------+---------+------+--------------+-------------+--+--+
| ACCOUNT_NUMBER | TRANSACTION_DATE | bal | Row# | RunningTotal | status | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 31/03/2015 | 82.61 | 4 | 82.61 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 31/03/2015 | 85.25 | 5 | 167.86 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 31/03/2015 | 93.61 | 6 | 261.47 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 30/04/2015 | 78.95 | 7 | 340.42 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 22/05/2015 | -62.04 | 8 | 278.38 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 31/05/2015 | 98.95 | 9 | 377.33 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 30/06/2015 | 79.5 | 10 | 456.83 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 15/07/2015 | -345.76 | 11 | 111.07 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 155 | 12/05/2016 | -111.07 | 12 | 0 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 31/03/2015 | 2.5 | 13 | 2.5 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 31/03/2015 | 2.5 | 14 | 5 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 31/03/2015 | 2.5 | 15 | 7.5 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 30/04/2015 | 2.5 | 16 | 10 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 31/05/2015 | 2.5 | 17 | 12.5 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 30/06/2015 | 0.67 | 18 | 13.17 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 30/07/2015 | -0.81 | 19 | 12.36 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 31/05/2018 | 5.08 | 20 | 17.44 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 30/11/2018 | 1.02 | 21 | 18.46 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 953 | 31/05/2019 | 1.48 | 22 | 19.94 | NOT_CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 31/03/2015 | 8.38 | 23 | 8.38 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 31/03/2015 | 10.65 | 24 | 19.03 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 31/03/2015 | 25.07 | 25 | 44.1 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 30/04/2015 | 12.21 | 26 | 56.31 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 30/04/2015 | -20 | 27 | 36.31 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 20/05/2015 | -36.31 | 28 | 0 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 31/05/2015 | -3.69 | 29 | -3.69 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 31/05/2015 | 13.17 | 30 | 9.48 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 30/06/2015 | 9 | 31 | 18.48 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| 961 | 25/07/2015 | -18.48 | 32 | 0 | CLEARED | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| | | | | | | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| | | | | | | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
| | | | | | | | |
+----------------+------------------+---------+------+--------------+-------------+--+--+
最佳答案
试一试。鉴于您提供的数据表,我假设您已经有了 RowNum 行。您或许可以对此进行改进,但这是一个开始。
;WITH CTE AS(
select t1.ACCOUNT_NUMBER AN3, t1.RowNum RN3
from #temp t1
CROSS APPLY(select ACCOUNT_NUMBER AN2,RowNum RN2
from #temp where RunningTotal=0) t2 where t1.ACCOUNT_NUMBER = t2.AN2 and t1.RowNum <= t2.RN2
)
select ACCOUNT_NUMBER,TRANSACTION_DATE,bal,RowNum,RunningTotal,Status,
CASE WHEN t2.AN3 IS NOT NULL THEN 'CLEARED'
ELSE 'NOT CLEARED' END Status
from #temp t1
LEFT JOIN CTE t2 on t1.ACCOUNT_NUMBER = t2.AN3 and t1.RowNum = t2.RN3
关于sql - 如何在运行总计达到零的帐户上应用状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57390253/
我已经下载了 RStudio,在打开我的代码所在的文件时,我似乎已经达到了容量限制: The file is 2.3MB the maximum file size is 2MB The file i
我有一个按钮,每次单击时,都会将 1 添加到变量中。当此变量超过 5 时,将触发警报。然而,此后触发器仍不断激活。我尝试使用 == 而不是 > 进行检查,但它做同样的事情。有什么想法吗? http:/
我正在将Slick 3.0与HikariCP 2.3.8一起使用(也可以玩2.4) 我做了很多数据库IO,并且不断达到队列限制。 有没有一种方法可以获取当前的队列大小,以及如何增加队列大小? 还是建议
在 Salesforce 中,您可以设置各种工作流程或构建用于发送电子邮件的 API 应用程序。对于大多数标准 Salesforce 组织,每天有 1000 封电子邮件的限制。 (例如,参见 here
我有一个类是这样的: public sealed class Contract { public bool isExpired { get; set; } public DateTim
我有一个带有特殊符号按钮的输入作为附加组件。 HTML
我正在尝试压缩 pdf 文件(有时是图像)。我需要一个 java 压缩器来帮助我压缩文件。我需要尺寸小于原始文档尺寸的一半。我尝试了java api中给出的deflator。但它并不是很成功。请帮我解
我正在使用这条线来创建淡入效果。 $('#div').css({opacity: 0, visibility:"visible"}).animate({opacity: 1}, 500); 可见类达到
我使用 URLCache 来缓存请求响应,最大容量如下: let diskCapacity = 100 * 1024 * 1024 let memoryCapacity = 100
我有一个计数器函数,我从这个 Answer 得到它: function countDown(i) { var int = setInterval(function () {
下面是一段代码,用于检查给定数字是否为 Lychrel 数字。这基本上意味着该程序取一个数及其倒数之和,然后取那个数及其倒数之和,等等,直到找到回文。如果它在一定的迭代次数内没有找到这样的数字(我在这
我即将对这个可怕的旧 Java Web 应用程序做一些工作,这是我的一个 friend 不久前继承的。 在我设置 tomcat、导入项目和所有这些到我的 eclipse 工作区后,我收到此错误,指出
我有一个 NSDictionary 对象,其中包含深层结构,例如包含包含字典的进一步数组的数组... 我想在层次结构中向下获取一个对象。是否有任何直接索引方法可以使用键名或其他方式获取它们? 多次调用
正如标题所说,我的 .border div 的边框跨度比它里面的要宽。它只会在达到 710px 时发生,因此您需要在 this fiddle 中展开结果窗口。 . 我希望边框保持在其内容周围而不超过它
我在 MySQL 中有一个表,通过 Microsoft Access 2013 中的链接表(通过 ODBC) Access 。 此表包含超过 124,000 条记录,我需要一个表单中的 ComboBo
一旦上一个输入达到其最大长度值,我如何才能聚焦下一个输入? a: b: c: 如果用户粘贴的文本大于最大长度,理想情况下它应该溢出到下一个输入。 jsFiddle: http://jsfiddl
我的任务是在客户的 QA 服务器上提供服务器性能报告。理想情况下,客户希望对约 900 个并发用户进行负载测试,因为这是他们在高峰时段通常使用的数量。然而,我一直在做的负载测试正在使他们的 QA 服务
我在 django 应用程序中对我的 celery worker 运行任务,其中每个任务执行大约需要 1-2 秒。通常这些执行都很好,但有时,特别是如果 Django 应用程序已经部署了一段时间,我开
我有一个 one_for_one 主管来处理类似且完全独立的 child 。 当一个 child 出现问题时,反复崩溃并触发: =SUPERVISOR REPORT==== 30-Mar-2011::
根据该网站,他们在免费计划中限制了 100 个并发连接,但是当第 101 个连接尝试连接时,它被拒绝,那么什么时候允许新连接? 例如:用户是否必须等待一定时间或一旦一个连接关闭,另一个连接就有机会连接
我是一名优秀的程序员,十分优秀!