Reputation: 77
I have a table in SQL Server 2008 with data below:
organization , number of request, date number of request
organization1, ID1139151, 2017-03-15 13:10:01.000
organization1, ID1139152, 2017-03-15 14:31:05.000
organization2, ID1139153, 2017-03-16 10:38:08.000
organization2, ID1139154, 2017-03-16 09:26:04.000
organization2, ID1139155, 2017-03-16 18:09:15.000
organization2, ID1139156, 2017-03-16 20:14:29.000
organization3, ID1139157, 2017-03-23 11:18:18.000
Help me to find a summ of days by every organization with help of SQL query.
Result:
organization , date number of request
organization1, 2
organization2, 4
organization3, 1
Thank you!
CREATE TABLE Mytable (
[organization] varchar(50) NOT NULL,
[number of request] varchar(15) NOT NULL,
[date_number_of_request] datetime NOT NULL,
)
INSERT INTO Mytable
VALUES
('organization1','ID1139151','2017-03-15 13:10:01.000'),
('organization1','ID1139152','2017-03-15 14:31:05.000'),
('organization2','ID1139153','2017-03-16 10:38:08.000'),
('organization2','ID1139154','2017-03-16 09:26:04.000'),
('organization2','ID1139155','2017-03-16 18:09:15.000'),
('organization2','ID1139156','2017-03-16 20:14:29.000'),
('organization3','ID1139157','2017-03-23 11:18:18.000');
Upvotes: 0
Views: 76
Reputation: 82474
Unless I'm missing something, a simple group by would do what you need:
SELECT organization,
COUNT([date_number_of_request]) As [date number of request]
FROM Mytable
GROUP BY organization
Result:
organization , date number of request
organization1, 2
organization2, 4
organization3, 1
Upvotes: 2
Reputation: 407
use the concept of group by in sql like below
Select organization ,count([date_number_of_request]) as 'date number of request'
from Mytable group by organization order by organization
Upvotes: 0