I'm trying to create a table in SQL that shows the difference in hours between each deposit for each user e.g (1st deposit Vs 2nd deposit, 2nd deposit Vs 3rd deposit, 3rd deposit Vs 4th deposit etc...)
here is the original table:
with q1 as (SELECT
[UserId],
[DepositAttemptDate],
[AmountSystem]
FROM [dbo].[v_DepositAttempts_Marketing]
WHERE [DepositAttemptDate] >= '2024-01-01' AND [Status] IN ('Completed', 'Complete', 'Confirmed') AND [DepositType]=''
ORDER BY [UserId] ASC, [DepositAttemptDate] DESC)
| User | Deposit Date | Value |
|---|---|---|
| 83815-fa85-466b-aaa7-00029c5 | 2024-10-30 12:42:58.793 | 8.698677800974 |
| 62ac8-5d7f-464a-993c-00039b1 | 2024-02-28 20:38:59.883 | 253.390000000000 |
| 62ac8-5d7f-464a-993c-00039b1 | 2024-02-28 19:09:26.323 | 253.390000000000 |
| 62ac8-5d7f-464a-993c-00039b1 | 2024-02-28 18:15:13.223 | 253.390000000000 |
| 62ac8-5d7f-464a-993c-00039b1 | 2024-02-28 17:54:17.340 | 253.390000000000 |
| 62ac8-5d7f-464a-993c-00039b1 | 2024-02-06 19:43:12.757 | 115.140000000000 |
| 62ac8-5d7f-464a-993c-00039b1 | 2024-01-30 13:36:56.937 | 253.390000000000 |
| 62ac8-5d7f-464a-993c-00039b1 | 2024-01-09 14:20:03.440 | 405.040000000000 |
| 17f62-01c7-4a9c-ba28-0003b7f | 2024-05-15 18:50:18.350 | 51.500000000000 |
| 17f62-01c7-4a9c-ba28-0003b7f | 2024-03-21 22:59:57.217 | 51.500000000000 |
| 17f62-01c7-4a9c-ba28-0003b7f | 2024-01-21 13:24:44.393 | 51.500000000000 |
| 17f62-01c7-4a9c-ba28-0003b7f | 2024-01-03 20:13:14.167 | 51.500000000000 |
| 76763-384a-46cb-9a08-0004393 | 2024-09-06 18:51:29.677 | 103.000000000000 |
| 76763-384a-46cb-9a08-0004393 | 2024-09-05 00:01:44.587 | 51.500000000000 |
| 76763-384a-46cb-9a08-0004393 | 2024-08-25 03:42:08.290 | 103.000000000000 |
[]) to delimit identify, and the schemadboimplies SQL Server, but you need to correct your post here.