I have the following table in SQL Server:
Date Browser Country Time(ms)
----------------------------------------------------------
2019-05-06 Chrome US 1000
2019-05-06 Chrome US 560
2019-05-07 Firefox JP 2300
2019-05-07 Edge US 1200
2019-05-07 Chrome JP 3000
2019-05-07 Chrome JP 3200
2019-05-07 Chrome JP 2100
2019-05-07 Firefox US 2200
I need to "bucketize" the results based on the time it took to complete. The end result would be something like this:
Time(ms) US JP
--------------------------------------
0-1s 2 0
1-2s 1 0
2-3s 1 2
3+s 0 2
The closest thing I was able is to do is a query like this:
SELECT
[Country],
COUNT(CASE WHEN [Time] >= 0 AND [Time] < 1000 THEN 1 END) AS '0 - 1s',
COUNT(CASE WHEN [Time] >= 1000 AND [Time] < 2000 THEN 1 END) AS '1 - 2s',
COUNT(CASE WHEN [Time] >= 2000 AND [Time] < 3000 THEN 1 END) AS '2 - 3s',
COUNT(CASE WHEN [Time] >= 3000 THEN 1 END) AS '+3s'
FROM [dbo].[MyTable]
GROUP BY [Country]
But this schema is not quite what I am looking for since my result is:
Country 0 - 1s 1 - 2s 2 - 3s +3s
---------------------------------------------------------
US 2 1 1 0
JA 0 0 2 2
How should I approach this problem?