//下面是我的查询,它给出了如下所示的结果集
Name, Cardno, date, Minimum In Time for day, MaximumOutTime for day
Guruprasad Marathe 14109393 03-06-2013 09:43 19:18
Guruprasad Marathe 14109393 04-06-2013 09:50 19:19
Guruprasad Marathe 14109393 05-06-2013 09:33 19:14
Guruprasad Marathe 14109393 06-06-2013 09:52 19:09
Guruprasad Marathe 14109393 07-06-2013 09:54 19:21
查询
WITH cte_tables (zcardno, zdate, zs_datetime, zchannel_no) AS
(
SELECT
cardno,
DATEADD(dd, DATEDIFF(dd, 0, s_datetime), 0),
s_datetime,
[channel no] as action
FROM
transactions
where
s_datetime >= '2013-03-01'
UNION ALL
SELECT
cardno,
DATEADD(dd, DATEDIFF(dd, 0, s_datetime), 0),
s_datetime,
Action
FROM
custom_transactions
where
s_datetime >= '2013-03-01'
),
cte_minmax (acardno, adate, aMinS_datetime, aMaxS_datetime) AS
(
SELECT
zcardno,
zdate,
MIN(zs_datetime),
NULL
FROM
cte_tables
WHERE
zchannel_no = 2
GROUP BY
zcardno,
zdate
UNION ALL
SELECT
zcardno,
zdate,
NULL,
MAX(zs_datetime)
FROM
cte_tables
WHERE
zchannel_no = 1
GROUP BY
zcardno,
zdate
)
SELECT
m.name,
c.acardno AS cardno,
REPLACE(CONVERT(VarChar(50), c.adate, 103),'/','-') AS [date],
LEFT(CONVERT(varchar,MAX(c.aMinS_datetime),108),5) AS InTime,
LEFT(CONVERT(varchar,MAX(c.aMaxS_datetime),108),5) AS OutTime
FROM cte_minmax c
inner join master m
on c.acardno = m.cardno
where acardno in ('14109393')
and adate between '2013-06-01' and '2013-06-08'
GROUP BY
m.name,
c.acardno,
c.adate
order by
c.acardno
现在我想要一个结果集,它将给所有In&员工在一天的时间安排,我想计算他们的差异作为员工的有效工作时间。
2 for Out Time& 1为时间
以下是In&为员工提供时间
Guruprasad Marathe 14109393 03-06-2013 2013-06-03 10:22:41.000 NULL
Guruprasad Marathe 14109393 03-06-2013 2013-06-03 09:43:39.000 NULL
Guruprasad Marathe 14109393 03-06-2013 2013-06-03 10:39:39.000 NULL
Guruprasad Marathe 14109393 03-06-2013 2013-06-03 13:49:27.000 NULL
Guruprasad Marathe 14109393 03-06-2013 2013-06-03 14:09:44.000 NULL
Guruprasad Marathe 14109393 03-06-2013 2013-06-03 15:18:34.000 NULL
Guruprasad Marathe 14109393 03-06-2013 2013-06-03 16:08:17.000 NULL
Guruprasad Marathe 14109393 03-06-2013 2013-06-03 16:44:55.000 NULL
Guruprasad Marathe 14109393 03-06-2013 NULL 2013-06-03 10:38:33.000
Guruprasad Marathe 14109393 03-06-2013 NULL 2013-06-03 10:22:13.000
Guruprasad Marathe 14109393 03-06-2013 NULL 2013-06-03 13:20:59.000
Guruprasad Marathe 14109393 03-06-2013 NULL 2013-06-03 14:09:16.000
Guruprasad Marathe 14109393 03-06-2013 NULL 2013-06-03 15:17:22.000
Guruprasad Marathe 14109393 03-06-2013 NULL 2013-06-03 16:07:51.000
Guruprasad Marathe 14109393 03-06-2013 NULL 2013-06-03 16:15:25.000
Guruprasad Marathe 14109393 03-06-2013 NULL 2013-06-03 19:18:28.000