本文介绍了如何将两个查询的结果存储在数据表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我对同一个访问2010数据库有两个查询。 第一个查询是通过使用where条件作为InOut =0来检索EmpID和InTime以及第二个查询来检索具有条件的EmpID和OutTime,其中InOut =1。 查询1如下:(分配给字符串变量) SELECT 格式(Min(Trans.Dt), MM / dd / yyyy HH:mm:ss) AS InTime,Trans.EmpID FROM Trans WHERE (格式(Trans.Dt, 短日期) in (' 8/25/2014')和 Trans.InOut = 0) GROUP BY 格式(Trans.Dt, 短日期),Trans.EmpID; 查询2如下:(分配给字符串变量) SELECT 格式(最大值(Trans.Dt) ), MM / dd / yyyy HH:mm:ss) AS OutTime,Trans.EmpID FROM Trans WHERE (格式(Trans.Dt) , 短日期) in ( ' 8/25/2014')和 Trans.InOut = 1) GROUP BY 格式(Trans.Dt, 短日期),Trans。 EmpID; 现在我已经创建了两个dbReader作为OLEDataReader来执行2个查询。 我需要一个显示EmpID,InTime(来自dbReader1,即query1)和OutTime(来自dbReader2即。,Query2)的数据表。 提前致谢!!! div class =h2_lin>解决方案 以下内容为您提供一次查询中输入和输出时间的所有结果: SELECT格式(Min(Trans.Dt),MM / dd / yyyy HH:mm:ss)AS InOutTime,Trans.EmpID FROM Trans WHERE(格式(Trans.Dt,短日期)in ('8/25/2014')和Trans.InOut =0)GROUP BY格式(Trans.Dt,短日期),Trans.EmpID UNION ALL SELECT格式(最大值( Trans.Dt),MM / dd / yyyy HH:mm:ss)AS InOutTime,Trans.EmpID FROM Trans WHERE(格式(Trans.Dt,短日期))('8/25/2014')和Trans.InOut =1)GROUP BY Fo rmat(Trans.Dt,短日期),Trans.EmpID; 这个给你进出时间不同的列: SELECT格式(Min(Trans.Dt),MM / dd / yyyy HH:mm:ss)AS InTime,' 'AS OutTime Trans.EmpID FROM Trans WHERE(格式(Trans.Dt,短日期)在('8/25/2014')和Trans.InOut =0)GROUP BY格式(Trans.Dt,Short日期),Trans.EmpID UNION ALL SELECT格式(Max(Trans.Dt),''InTime,'MM / dd / yyyy HH:mm:ss)AS OutTime,Trans。 EmpID FROM Trans WHERE(格式(Trans.Dt,短日期)在('8/25/2014')和Trans.InOut =1)GROUP BY格式(Trans.Dt,短日期),Trans .EmpID; 这可以为每个EmpID提供单行进出时间 SELECT EmpID,MIN(InTime) as InTime,Max(OutTime) ) as OutTime FROM ( SELECT 格式(Min(Trans.Dt), MM / dd / yyyy HH:mm:ss) AS InTime,' ' AS OutTime Trans.EmpID FROM Trans WHERE (格式(Trans.Dt, 中的 ' 8/25/2014')和 Trans.InOut = 0) GROUP BY 格式(Trans.Dt, 短日期),Trans.EmpID UNION ALL SELECT 格式(Max(Trans.Dt),' ' 作为 InTime, MM / dd / yyyy HH:mm:ss) AS OutTime,Trans.EmpID FROM Trans WHERE (格式(Trans.Dt, 短日期) in (' 8/25/2014')和 Trans.InOut = 1) GROUP BY 格式(Trans.Dt, 短日期),Trans.EmpID; ) GROUP BY EmpID 如果此解决方案解决了您的问题,请花一些时间接受它,以便其他人可以受益。谢谢 试试这个 SELECT格式(Max(Trans.Dt),MM / dd / yyyy HH:mm:ss)AS OutTime,格式(Min(Trans.Dt),MM / dd / yyyy HH:mm:ss)AS InTime,Trans.EmpID FROM Trans WHERE(格式(Trans.Dt) ,短日期,('8/25/2014')和(Trans.InOut =0或Trans.InOut =1))GROUP BY格式(Trans.Dt,短日期),Trans .EmpID; I have got two queries for the same access 2010 database.the first query is to retrieve the EmpID and InTime by using the where condition as InOut="0" and teh second query to retrieve the EmpID and the OutTime with condition Where InOut="1".the query 1 as follows:(which is assigned to a string variable)SELECT Format(Min(Trans.Dt),"MM/dd/yyyy HH:mm:ss") AS InTime, Trans.EmpID FROM Trans WHERE (Format(Trans.Dt,"Short Date") in ('8/25/2014') and Trans.InOut="0") GROUP BY Format(Trans.Dt,"Short Date"), Trans.EmpID;The query 2 as follows:(which is assigned to a string variable)SELECT Format(Max(Trans.Dt),"MM/dd/yyyy HH:mm:ss") AS OutTime, Trans.EmpID FROM Trans WHERE (Format(Trans.Dt,"Short Date") in ('8/25/2014') and Trans.InOut="1") GROUP BY Format(Trans.Dt,"Short Date"), Trans.EmpID;now I have created two dbReader respectively as OLEDataReader for executing the 2 queries.The I need a datatable that displays EmpID ,InTime (from dbReader1 ie.,query1) and OutTime(from dbReader2 ie.,Query2).Thanks in advance!!! 解决方案 The following gives you all the results with your in and out times in one query:SELECT Format(Min(Trans.Dt),"MM/dd/yyyy HH:mm:ss") AS InOutTime, Trans.EmpID FROM Trans WHERE (Format(Trans.Dt,"Short Date") in ('8/25/2014') and Trans.InOut="0") GROUP BY Format(Trans.Dt,"Short Date"), Trans.EmpIDUNION ALLSELECT Format(Max(Trans.Dt),"MM/dd/yyyy HH:mm:ss") AS InOutTime, Trans.EmpID FROM Trans WHERE (Format(Trans.Dt,"Short Date") in ('8/25/2014') and Trans.InOut="1") GROUP BY Format(Trans.Dt,"Short Date"), Trans.EmpID;This one gives you the in and out time inseparate columns:SELECT Format(Min(Trans.Dt),"MM/dd/yyyy HH:mm:ss") AS InTime,'' AS OutTime Trans.EmpID FROM Trans WHERE (Format(Trans.Dt,"Short Date") in ('8/25/2014') and Trans.InOut="0") GROUP BY Format(Trans.Dt,"Short Date"), Trans.EmpIDUNION ALLSELECT Format(Max(Trans.Dt),'' As InTime, "MM/dd/yyyy HH:mm:ss") AS OutTime, Trans.EmpID FROM Trans WHERE (Format(Trans.Dt,"Short Date") in ('8/25/2014') and Trans.InOut="1") GROUP BY Format(Trans.Dt,"Short Date"), Trans.EmpID;This should give you in and out times in single row for each EmpIDSELECT EmpID, MIN(InTime) as InTime, Max(OutTime) as OutTimeFROM(SELECT Format(Min(Trans.Dt),"MM/dd/yyyy HH:mm:ss") AS InTime,'' AS OutTime Trans.EmpID FROM Trans WHERE (Format(Trans.Dt,"Short Date") in ('8/25/2014') and Trans.InOut="0") GROUP BY Format(Trans.Dt,"Short Date"), Trans.EmpIDUNION ALLSELECT Format(Max(Trans.Dt),'' As InTime, "MM/dd/yyyy HH:mm:ss") AS OutTime, Trans.EmpID FROM Trans WHERE (Format(Trans.Dt,"Short Date") in ('8/25/2014') and Trans.InOut="1") GROUP BY Format(Trans.Dt,"Short Date"), Trans.EmpID;)GROUP BY EmpIDIf this solution solves your problem, please take some time to accept it so others can benefit. Thank youTry thisSELECT Format(Max(Trans.Dt),"MM/dd/yyyy HH:mm:ss") AS OutTime, Format(Min(Trans.Dt),"MM/dd/yyyy HH:mm:ss") AS InTime, Trans.EmpID FROM Trans WHERE (Format(Trans.Dt,"Short Date") in ('8/25/2014') and (Trans.InOut="0" or Trans.InOut="1")) GROUP BY Format(Trans.Dt,"Short Date"), Trans.EmpID; 这篇关于如何将两个查询的结果存储在数据表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-15 20:41