Я пытаюсь разделить на столбцы последующее действие, которое произошло последовательно, поэтому первое действие, второе действие, третье действие. Я думаю, что могу использовать SyncDate, чтобы разделить последующие действия, но не знаю лучшего способа сделать это.
Я связал, используя функцию row_number, но это не правильно перечисляет RowNo. Я думал об использовании CTE для разделения трех действий.
Это то, что у меня есть до сих пор
SELECT [RM-JOB].[Job-No] [Visit no]
, cast(ard.SyncDate as date) [SyncDate]
, ard.actionref
, ard.FollowUpReq [FOLLOW ON]
, ARD.GeneralComments [FOLLOW ON ACTION]
, ROW_NUMBER()over(partition by [RM-JOB].[Job-No], cast(ard.SyncDate as date), ard.actionref order by ard.actionref, cast(ard.SyncDate as date) desc) AS 'RowNo'
FROM [CYHSQL01].[TM_FireRiskAssessment].[dbo].[ActionRequiredDetails] ARD right outer JOIN
[CYHSQL01].[TM_FireRiskAssessment].[dbo].ActionRequired AR ON ARD.ResultId = AR.ResultId inner join
[RM-JOB] on AR.JobNo = [RM-JOB].[Job-No]
Это дает следующие результаты, ниже также можно рассматривать как данные.
Visit no SyncDate actionref FOLLOW ON FOLLOW ON ACTION RowNo
10233639 NULL NULL NULL NULL 1
10233639 NULL NULL NULL NULL 1
10233639 03/10/2019 CP31 No Have visited all properties. All properties look to be compliant. 1
10233639 03/10/2019 CP31 No Have visited all properties. All properties look to be compliant. 1
10233639 03/10/2019 CP33 Yes I’m not sure whether roof space is fire resistant. I will arrange for someone to inspect this. 1
10233639 04/10/2019 CP33 Yes I’m not sure whether roof space is fire resistant. I will arrange for someone to inspect this. 2
10233639 04/10/2019 CP33 No Roofs Ltd will attend on 12/10/19 2
10233649 03/10/2019 CP31 No All doors are fire compliant. 1
10233649 03/10/2019 CP31 No All doors are fire compliant. 1
10233649 04/10/2019 CP33 Yes I will arrange for a contractor to carry out the inspection. 2
10233649 04/10/2019 CP33 No I’ve arranged an appointment with the contractor to attend on 23/10/19 2
10233649 05/10/2019 CP33 Yes I will arrange for a contractor to carry out the inspection. 3
10233649 05/10/2019 CP33 No I’ve arranged an appointment with the contractor to attend on 23/10/19 3
10233652 04/10/2019 CB8 No Cardboard box was empty so I removed it from the communal area. 1
10233652 04/10/2019 CB8 No Cardboard box was empty so I removed it from the communal area. 1
10233652 04/10/2019 CB8 No Cardboard box was empty so I removed it from the communal area. 1
10233652 05/10/2019 CP32 No All doors were checked and are fire resistant. 2
10233652 05/10/2019 CP32 No All doors were checked and are fire resistant. 2
10233652 05/10/2019 CP32 No All doors were checked and are fire resistant. 2
10233652 06/10/2019 CP33 Yes I will arrange for a contractor to inspect this. 3
10233652 06/10/2019 CP33 No Contractor has been booked and will attend on 20/10/19 3
10233652 06/10/2019 CP33 Yes I will arrange for a contractor to inspect this. 3
10233652 06/10/2019 CP33 No Contractor has been booked and will attend on 20/10/19 3
Кто-нибудь знает способ сделать это?
Спасибо за любую помощь!