如何在asp.net中采取先进先出时间数据和显示c# [英] How do in take First In Last out time data and display in asp.net c#
问题描述
我的下表有列。
aDate aTime EmpCode EmpName aDateTime
27-Dec-11 9:31 32 Amarnath KP 12/27/11 9:31
27- 12月11日9:42 32 Amarnath KP 12/27/11 9:42
27-Dec-11 10:01 32 Amarnath KP 12/27/11 10:01
27-Dec-11 14:10 32 Amarnath KP 12/27/11 14:10
27-Dec-11 14:11 32 Amarnath KP 12/27/11 14:11
27-Dec-11 14:13 32 Amarnath KP 12/27/11 14:13
27-Dec-11 14:46 32 Amarnath KP 12/27/11 14 :46
27-Dec-11 20:46 32 Amarnath KP 12/27/11 20:46
我想显示如下记录(参数从日期和到目前为止)
EmpCode FirstIN LastOUT
32 9.31 20.46
谢谢
Hi,
I have the below table with columns.
aDate aTime EmpCode EmpName aDateTime
27-Dec-11 9:31 32 Amarnath KP 12/27/11 9:31
27-Dec-11 9:42 32 Amarnath KP 12/27/11 9:42
27-Dec-11 10:01 32 Amarnath KP 12/27/11 10:01
27-Dec-11 14:10 32 Amarnath KP 12/27/11 14:10
27-Dec-11 14:11 32 Amarnath KP 12/27/11 14:11
27-Dec-11 14:13 32 Amarnath KP 12/27/11 14:13
27-Dec-11 14:46 32 Amarnath KP 12/27/11 14:46
27-Dec-11 20:46 32 Amarnath KP 12/27/11 20:46
I want to display the records like below(Parameters From Date and To date)
EmpCode FirstIN LastOUT
32 9.31 20.46
Thanks
推荐答案
您好,
您需要使用此表格进行自我加入,如下所示:
Hi,
You need to use self join with this table as below:
SELECT EmpIN.EmpCode,
EmpIn.EmpName,
EmpIn.FirstIN,
EmpOut.LastOut
FROM (SELECT EmpCode,
EmpName,
aDate,
MIN(aTime) AS [FirstIN]
FROM tblINOUT
GROUP BY EmpCode,EmpName, aDate) AS EmpIN
LEFT OUTER JOIN
(SELECT EmpCode,
EmpName,
aDate,
MAX(aTime) AS [LastOut]
FROM tblINOUT
GROUP BY EmpCode,,EmpName, aDate) AS EmpOUT
ON EmpIN.EmpCode = EmpOUT.EmpCode
AND EmpIN.aDate = EmpOUT.aDate;
在一个查询中不可能..
我们必须进行两次查询才能获得输出..
在第一个查询中,按升序排序FirstIN列...
In第二个查询只是按降序排序LastOUT列....
例如。
It is Not Possible in one Query..
our have to take two query for getting your output..
In a first query just sort FirstIN Column in ascending order ...
In Second query just sort LastOUT Column in Descending order....
For Example.
Select EmpCode,FirstIN from tblName order by FirstIN asc
Select EmpCode,LastOUT from tblName order by LastOUT desc
谢谢
AARIF SHAIKH
Thanks
AARIF SHAIKH
这篇关于如何在asp.net中采取先进先出时间数据和显示c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!