是什么导致RANK仅显示奇数

时间:2019-03-27 17:13:22

标签: sql tsql

我有一个查询正在提取发票对帐单的历史列表。我正在对帐单日期使用RANK()OVER PARTITION。结果集仅显示奇数(1、3、5、7等),有人知道它跳过偶数的原因吗?

select Distinct  
TPB805_STMT_TAG_HISTORY.ivo_int_id
,TPB805_STMT_TAG_HISTORY.vst_int_id
,TPB805_STMT_TAG_HISTORY.step_action_dt
,RANK() OVER (PARTITION BY TPB805_STMT_TAG_HISTORY.vst_int_id ORDER BY TPB805_STMT_TAG_HISTORY.step_action_dt) as 'RankNo'

from TPB805_STMT_TAG_HISTORY
join TSM603_EVENT_ACTION on TPB805_STMT_TAG_HISTORY.path_int_id = TSM603_EVENT_ACTION.path_int_id

WHERE TPB805_STMT_TAG_HISTORY.vst_int_id = 4564791

以下是TPB805文件的示例:

stmt_tag_hist_int_id    ivo_int_id  tickler_int_id  pat_nte_int_id  vst_int_id  path_int_id ar_letter_int_id    stmt_path_ctrl_int_id   stmt_path_tag_int_id    stmt_ctl_hist_int_id    row_sta_cd  lst_mod_id  lst_mod_ts  step_action_dt  interval_next_step  step_seq_no bad_debt_writeoff_fg    deny_ins_fg stmt_msg_int_id pymt_activity_msg_int_id    stmt_msg_txt_lint_1 stmt_msg_txt_lint_2 stmt_msg_txt_lint_3 stmt_msg_txt_lint_4 stmt_msg_txt_lint_5 stmt_msg_txt_lint_6 stmt_msg_txt_lint_7 stmt_msg_txt_lint_8 pymt_restart_seq    amt_due bgn_amt_due pymt_override_int_id    last_pmt_int_id last_chg_int_id bgn_pmt_int_id  bgn_chg_int_id  org_int_id  msg_ext_id  agent_int_id    guar_int_id new_chgs    new_pmts    guar_ext_id stmt_nbr    type_of_detail
5327    4600010 NULL    NULL    4564791 4   NULL    6   9969    32  A   SYSTEM                  25:27.4 00:00.0 30  1   N   N   1   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    327010.58   0   NULL    9530    223163  0   0   388 NS-No Statement NULL    645531  4026073.25  -3699062.67 NULL    0   D
51304   4600010 105 NULL    4564791 4   NULL    6   9969    276 A   SYSTEM                  21:54.5 26:01.6 30  2   N   N   1   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    327010.58   0   NULL    9530    223163  0   0   388 NS-No Statement NULL    645531  4026073.25  -3699062.67 NULL    0   D
102883  4600010 105 NULL    4564791 4   NULL    6   9969    556 A   SYSTEM                  19:34.9 22:05.5 30  2   N   N   1   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    327010.58   0   NULL    9530    223163  0   0   388 NS-No Statement NULL    645531  4026073.25  -3699062.67 NULL    0   D
170303  4600010 105 NULL    4564791 4   NULL    6   9969    863 A   SYSTEM                  28:10.8 19:40.3 30  2   N   N   1   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    271022.68   0   NULL    194530  223163  0   0   388 NS-No Statement NULL    645531  4026073.25  -3755050.57 NULL    0   D
241658  4600010 105 NULL    4564791 4   NULL    6   9969    1172    A   SYSTEM                  25:53.3 28:15.8 30  2   N   N   1   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    271022.68   0   NULL    194530  223163  0   0   388 NS-No Statement NULL    645531  4026073.25  -3755050.57 NULL    0   D
308604  4600010 105 NULL    4564791 4   NULL    6   9969    1482    A   SYSTEM                  30:52.2 25:56.5 30  2   N   N   1   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    271022.68   0   NULL    194530  223163  0   0   388 NS-No Statement NULL    645531  4026073.25  -3755050.57 NULL    0   D
430404  4600010 105 NULL    4564791 4   NULL    6   9969    1992    A   SYSTEM                  47:19.8 30:57.6 30  2   N   N   1   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    65527.83    0   NULL    566188  223163  0   0   388 NS-No Statement NULL    645531  4026073.25  -3960545.42 NULL    0   D
508328  4600010 105 NULL    4564791 4   NULL    6   9969    2317    A   SYSTEM                  24:25.4 47:23.4 30  2   N   N   1   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    65527.83    0   NULL    566188  223163  0   0   388 NS-No Statement NULL    645531  4026073.25  -3960545.42 NULL    0   D
581930  4600010 105 NULL    4564791 4   NULL    6   9969    2683    A   SYSTEM                  31:40.6 24:28.8 30  2   N   N   1   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    65527.83    0   NULL    566188  223163  0   0   388 NS-No Statement NULL    645531  4026073.25  -3960545.42 NULL    0   D
648669  4600010 105 NULL    4564791 4   NULL    6   9969    3055    A   SYSTEM                  41:14.5 31:45.1 30  2   N   N   1   NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    65527.83    0   NULL    566188  223163  0   0   388 NS-No Statement NULL    645531  4026073.25  -3960545.42 NULL    0   D

这是TSM603表中的数据:

row_sta_cd  override_label  lst_mod_id  event_action_int_id path_time_int_id    path_int_id path_event_int_id   action_int_id   statement_sw    aging_days  lst_mod_ts  action_type bill_sw msg_override    default_msg msg_id  des_usr_int_id
A   ALL INS                 sziegler                10  18  4   4   4   1   0   41:59.5 3   NULL    NULL    NULL    6   NULL
A   Final Bill              sziegler                137 73  4   3   5   NULL    5   00:33.2 4   1   NULL    NULL    NULL    NULL

这是结果列表的示例:

ivo_int_id  vst_int_id  step_action_dt  RankNo
4600010  4564791    2017-04-04 00:00     1
4600010  4564791    2017-05-11 00:26     3
4600010  4564791    2017-06-11 00:22     5
4600010  4564791    2017-07-12 00:19     7
4600010  4564791    2017-08-12 00:28     9
...

1 个答案:

答案 0 :(得分:0)

在@JNevil建议共享两个文件中的某些数据时,我发现每个发票对帐单都有2个操作:操作3用于“开始声明处理”,操作4用于“开始保险通知”

链接两个表时,它在每个发票语句中创建了2行输出(每个动作一行),并且由于我没有将报告中的“动作”拖入结果集中并使用DISTINCT,因此只显示了一行并跳过另一个。

当我将限定条件“ TSM603_EVENT_ACTION.action_type = 3”添加到WHERE语句时,RANK将按预期工作。

只要我有资格参加任何一项操作,RANK就会按预期运行,否则会跳过偶数