【发布时间】:2020-07-29 09:18:12
【问题描述】:
我有一个表格,其中包含帐号、交易日期、交易分行和金额。
我想生成一个包含以下信息的列:
如果该特定客户在同一天从不同的分支机构进行了交易。
结果示例如下:
AccountNumber Transaction_branch tran_Date Amount Different_Branch_Tran
11452 331 20/07/2020 500 no
11452 331 21/07/2020 500 no
5432 14 22/07/2020 500 no
5432 14 22/07/2020 500 no
11452 14 24/07/2020 500 yes
11452 420 24/07/2020 500 yes
11452 14 26/07/2020 500 no
如果客户在同一天进行了相同数量的交易,我有一个代码可以显示我。但是我不知道如何修改或更改此代码以获得我想要的结果。
select
a.*,
case when count(*) over(partition by trandate, accountnumber, amount) > 1 then 'Yes' else 'No' end SameAmountSameDay
from Tran_table a
where trandate> '20190701'
【问题讨论】:
标签: sql-server count partition case-when