I have a table of data as below in SQL Server:
+-------+------------+-------------------------+--------------------------+
| ID | IP | Date | NumFails |
+-------+------------+-------------------------+--------------------------+
| 21365 | 172.16.2.1 | 2016-05-16 00:20:54.000 | 200 |
| 21457 | 172.16.3.1 | 2016-05-16 00:21:05.000 | 295 |
| 21478 | 172.16.4.1 | 2016-05-16 00:22:46.000 | 128 |
| 24255 | 172.16.2.1 | 2016-05-16 12:22:01.000 | 213 |
| 24318 | 172.16.3.1 | 2016-05-16 12:22:12.000 | 297 |
| 24366 | 172.16.4.1 | 2016-05-16 12:23:52.000 | 243 |
| 25699 | 172.16.2.1 | 2016-05-16 18:21:31.000 | 226 |
| 25794 | 172.16.3.1 | 2016-05-16 18:21:41.000 | 347 |
| 25811 | 172.16.4.1 | 2016-05-16 18:22:51.000 | 270 |
| 27142 | 172.16.2.1 | 2016-05-17 00:22:45.000 | 227 |
| 27193 | 172.16.3.1 | 2016-05-17 00:22:55.000 | 347 |
| 27251 | 172.16.4.1 | 2016-05-17 00:23:59.000 | 270 |
+-------+------------+-------------------------+--------------------------+
I have an idea of how to do this programmatically, but I'm too new to SQL to know how to do this: I want to get the delta of NumFails given a specific time period. For this, I want to be able to do a query that:
Selects IP address from time period A (<2016-05-17 01:00:00.000 and >2016-05-17 00:00:00.000) and matching IP address from time period B (<2016-05-16 01:00:00.000 and >2016-05-16 00:00:00.000) and returns IP address and the difference from period A numfails result MINUS period b numfails result. This is done for every unique IP address in time period A (all are unique) comparing against time period B.
Any easy way to do such a thing? I want to run the report on a daily basis, so period A will shift to today's date, and period B will be the previous day's date. I can pre-populate that with the calling SQL, but I have no clue what to build to grab the two values and do the difference and report.