Hi @AngelX10 ,
Welcome to the microsoft TSQL Q&A forum!
For this type of question it is always a good idea to post CREATE TABLE statements for your tables and INSERT statements with the sample data, enough to illustrate all angles of the problem.
The idea of creating a duration column based on the data you have does not seem to be easy to implement.
Please refer to the following code for the currently achievable part:
CREATE TABLE #yourtable(ID INT,[Date] date,Phone INT,[Duration(Sec)] INT)
INSERT INTO #yourtable VALUES(1,'1/2/2021',15625,9),(2,'1/2/2021',15789,1),(3,'1/2/2021',15456,12)
,(4,'1/2/2021',15462,10),(5,'1/2/2021',15236,15)
;WITH cte
as(SELECT CASE WHEN [Duration(Sec)]<1 THEN '<1'
WHEN [Duration(Sec)] BETWEEN 1 AND 5 THEN '1-5'
WHEN [Duration(Sec)] BETWEEN 6 AND 10 THEN '6-10'
WHEN [Duration(Sec)] BETWEEN 11 AND 15 THEN '11-15'
WHEN [Duration(Sec)] BETWEEN 16 AND 20 THEN '16-20' END Duration
FROM #yourtable)
SELECT Duration,COUNT(Duration) FROM cte
GROUP BY Duration
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.