SQL Server:仅在包含特定文本的行之后直接过滤行

时间:2017-02-20 20:29:14

标签: sql sql-server pandas indexing filter

我有一个包含以下列的表

application_uuid
changed_at_utc
changed_by 
name

我想按application_uuidchanged_at_utc排序。然后,我想仅过滤直接来自application_status文本“准备评分”的行之后的行

使用Python和Pandas,我会做这样的事情......

application_statuses = application_statuses.sort_values(['application_uuid', 'changed_at_utc'], ascending=[True, True]).reset_index(drop=True)
indexes = application_statuses[application_statuses['application_status']=='Ready for Scoring'].index + 1
next_statuses = application_statuses.ix[indexes]

如何使用SQL执行相同的操作?

1 个答案:

答案 0 :(得分:3)

根据您的解释,您可以使用Project Solution Unit Testing Project UnitTestClass.cs CodedUI Testing Project CodedUITests.cs CodedUIMap.uitest Testing Utilities Project HelperFile1.cs HelperFile2.cs Database Project Insert whatever here Services Project your web services Web Project Your View and Controller files etc. 功能执行此操作。

lead

如果必须为每个select next_application_status,application_uuid,changed_at_utc,changed_by from (select t.*, lead(application_status) over(order by application_uuid,changed_at_utc) as next_appliaction_status from tablename t ) t1 where application_status = 'Ready for Scoring' 执行此操作,请在application_uuid中添加partition by,如下所示。

lead

如果在application_status select next_application_status,application_uuid,changed_at_utc,changed_by from (select t.*, lead(application_status) over(partition by application_uuid order by changed_at_utc) as next_appliaction_status from tablename t ) t1 where application_status = 'Ready for Scoring' 之后需要 all 行,请获取该特定行的时间戳并选择所有其他更大的时间戳。这假设application_uuid最多只有一行Ready for Scoring状态。

Ready for Scoring