SQL CTE以Sybase IQ连续识别30天

时间:2017-12-12 00:40:32

标签: sql sybase-iq

我需要识别成员/提供者(创建一个名为:PRV_MBR_KEY的密钥),他们有30个连续的服务日期,没有休息。我已经在SQL SVR中成功测试和验证了样本数据。我需要重新编写代码以在Sybase IQ平台中工作。

示例数据:

PRV_MBR_KEY             FDOS_LN
330800913-00369544518   10/10/2016
330800913-00369544518   10/11/2016
330800913-00369544518   10/12/2016
330800913-00369544518   10/13/2016
330800913-00369544518   10/14/2016
330800913-00369544518   10/15/2016
330800913-00369544518   10/16/2016
330800913-00369544518   10/17/2016
330800913-00369544518   10/18/2016
330800913-00369544518   10/19/2016

以下是适用的SQL代码:

WITH CTE AS (
SELECT  PRV_MBR_KEY,
[FDOS_LN],
RangeId = DATEDIFF(DAY, 0, [FDOS_LN])
- ROW_NUMBER() OVER (PARTITION BY PRV_MBR_KEY ORDER BY [FDOS_LN])
FROM TEST_table)
SELECT PRV_MBR_KEY,
StartDate=MIN([FDOS_LN]),
EndDate=MAX([FDOS_LN]),
DAYCOUNT=DATEDIFF(DAY,MIN([FDOS_LN]),MAX([FDOS_LN]))+1
FROM CTE
GROUP BY PRV_MBR_KEY,RangeID
HAVING DATEDIFF(DAY,MIN([FDOS_LN]),MAX([FDOS_LN]))+1>=30
ORDER BY PRV_MBR_KEY,MIN([FDOS_LN])

预期结果:

PRV_MBR_KEY             StartDate   EndDate     DAYCOUNT
330800913-00369544518   2016-10-10  2016-11-13  35
330800913-00565274557   2017-01-26  2017-02-24  30


The error I get when running code in Sybase IQ:
[Sybase][ODBC Driver][Sybase IQ]Data exception - argument must be DATE or 
DATETIME  --(dflib/dfe_datepart.cxx 1450)

0 个答案:

没有答案