I have a table that looks like this
id | name | CreatedDate |
---|---|---|
1 | test1 | 2014-06-30 09:00:00 |
1 | test2 | 2014-06-30 09:01:10 |
1 | test3 | 2014-06-30 09:01:23 |
1 | test4 | 2014-06-30 09:01:43 |
1 | test5 | 2014-06-30 09:02:02 |
1 | test6 | 2014-06-30 09:02:34 |
1 | test7 | 2014-06-30 09:03:22 |
1 | test8 | 2014-06-30 09:03:28 |
1 | test9 | 2014-06-30 09:04:14 |
1 | test10 | 2014-06-30 09:04:22 |
1 | test11 | 2014-06-30 09:04:28 |
I want to get the number of inserts that have happened per minute so the output looks like this
Inserts Per Min | Start Time | End Time |
---|---|---|
1 | 09:00:00 | 09:00:00 |
3 | 09:01:10 | 09:01:43 |
2 | 09:02:02 | 09:00:34 |
2 | 09:03:22 | 09:03:28 |
3 | 09:04:14 | 09:04:28 |
How can I do that? This is the code that I have that gives me the Inserts per day but I can't get this to work per minute
Select Count(CreatedDate) as InsertsPerDay, Convert(varchar, CreatedDate, 101) as CreatedDate
From MyTable
Where DATEDIFF(day, CreatedDate, GETDATE())) < 30
Group By Convert(varchar, CreatedDate, 101)
Order By InsertsPerDay DESC