我在SQL Server 2008中的表如下數據:如何計算工作日數?
user ,number of request, date number of request
user1, ID1139151, 2017-03-15 13:10:01.000
user1, ID1139152, 2017-03-13 14:31:05.000
user2, ID1139153, 2017-03-16 10:38:08.000
user2, ID1139154, 2017-03-16 09:26:04.000
user2, ID1139155, 2017-03-17 18:09:15.000
user2, ID1139156, 2017-03-17 20:14:29.000
user2, ID1139157, 2017-03-28 11:18:18.000
幫我用SQL查詢的幫助每一位用戶發現天的SUMM。
Result:
user, date number of request
user1, 2
user2, 3
腳本來創建數據:
CREATE TABLE Mytable (
[user] varchar(50) NOT NULL,
[number of request] varchar(15) NOT NULL,
[date_number_of_request] datetime NOT NULL, )
INSERT INTO Mytable
VALUES
('user1','ID1139151','2017-03-15 13:10:01.000'),
('user1','ID1139152','2017-03-13 14:31:05.000'),
('user2','ID1139153','2017-03-16 10:38:08.000'),
('user2','ID1139154','2017-03-16 09:26:04.000'),
('user2','ID1139155','2017-03-17 18:09:15.000'),
('user2','ID1139156','2017-03-17 20:14:29.000'),
('user2','ID1139157','2017-03-28 11:18:18.000');
加1的樣本數據,前進嘗試包括你已經嘗試以及 – TheGameiswar
一種方法的任何企圖是添加[日曆表(http://www.sqlservercentral.com/blogs/dwainsql/ 2014/03/30/calendar-tables-in-t-sql /)到你的數據庫。這可以用來過濾非工作日。銀行假期不能被識別,除非你將它們存儲在某個地方。 –