我在获取以下方案所需的输出时遇到问题。
name | provider | visit_dt | rd | rn
A | 100000 | 06/05/'17 | 1 | 1
B | 100000 | 06/05/'17 | 1 | 0
B | 100001 | 06/05/'17 | 1 | 1
C | 100001 | 06/03/'17 | 1 | 1
D | 100001 | 06/05/'17 | 1 | 0
这里有4种不同的场景:
所以预期的输出应该如下。
Var Bit
System::Call "kernel32::GetCurrentProcess()i.s"
System::Call "kernel32::IsWow64Process(is,*i.r0)"
StrCmpS $0 0 +3
StrCpy $Bit 64
Goto +2
StrCpy $Bit 32
如果有人能帮助我解决这个问题,那将会很棒。
任何建议都会令人感激。
提前谢谢。
答案 0 :(得分:1)
如果这是SQL 2008+,我相信这会有效(只要visit_dt是日期数据类型)。
0:00:02.798704
0:00:02.940005
0:00:03.039798
http://dbfiddle.uk/?rdbms=sqlserver_2014&fiddle=1dc1bf626aed520d601fe68f1f11be55
答案 1 :(得分:0)
这看起来你的方法有些矛盾:
Select * from (
Select *, Con1 = Row_Number() over(Partition by [name] order by visit_dt desc) ,
Con2 = Row_Number() over(partition by [name],[rn] order by visit_dt desc)
from yourVisits
) a
Where (a.Con1 = 1 and rd =1 and rn = 1)
or (a.Con2 = 1 and rn=1)
or (a.Con2 = 1 and rn=0)