asked on
DECLARE @Table TABLE (classes tinyint, [time] smalldatetime, agentname char(2))
INSERT @Table (classes, [time], agentname)
VALUES (2, '8/26/13 6:00', 'a1'),
(2, '8/26/13 6:00', 'a2'),
(1, '8/26/13 6:00', 'a3'),
(1, '8/26/13 6:00', 'a1'),
(1, '8/26/13 6:00', 'a5'),
(1, '8/26/13 6:15', 'a1'),
(1, '8/26/13 6:15', 'a2'),
(1, '8/26/13 6:15', 'a3'),
(2, '8/26/13 6:15', 'a4'),
(1, '8/26/13 6:15', 'a5'),
(2, '8/26/13 6:30', 'a2'),
(2, '8/26/13 6:30', 'a3'),
(2, '8/26/13 6:30', 'a5')
SELECT [time],
COUNT(DISTINCT agentname)
FROM @table
GROUP BY [time]
Here is the output:Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.
TRUSTED BY
from (
select disctinct time, agentname from YourTable
) as A
group by time