使用Access 2003
查询
SELECT t1.PERSONID ,t1.CARDEVENTDATE
,MIN(t2.CARDEVENTTIME) AS Intime
,MAX(t3.CARDEVENTTIME) AS Outtime,
Min(t3.Cardeventtime) as BreakOut,
Max(t4.CardEventTime) as BreakIn
FROM ( ( ( SELECT PERSONID
, CARDEVENTDATE
FROM T_CARDEVENT ) as t1
LEFT OUTER JOIN (SELECT PERSONID
,CARDEVENTDATE, FUNCTION
, CARDEVENTTIME
FROM T_CARDEVENT WHERE (FUNCTION = 'A')) as t2
ON t1.PERSONID = t2.PERSONID
AND t1.CARDEVENTDATE = t2.CARDEVENTDATE) LEFT OUTER JOIN (SELECT PERSONID
,CARDEVENTDATE, FUNCTION
, CARDEVENTTIME
FROM T_CARDEVENT WHERE (FUNCTION = 'D')) as t3
ON t1.PERSONID = t3.PERSONID
AND t1.CARDEVENTDATE = t3.CARDEVENTDATE ) LEFT OUTER JOIN (SELECT PERSONID
,CARDEVENTDATE, FUNCTION
, CARDEVENTTIME
FROM T_CARDEVENT WHERE (FUNCTION = 'B')) as t4
ON t1.PERSONID = t4.PERSONID
AND t1.CARDEVENTDATE = t4.CARDEVENTDATE ) LEFT OUTER JOIN (SELECT PERSONID
,CARDEVENTDATE, FUNCTION
, CARDEVENTTIME
FROM T_CARDEVENT WHERE (FUNCTION = 'C')) as t5
ON t1.PERSONID = t5.PERSONID
AND t1.CARDEVENTDATE = t5.CARDEVENTDATE
GROUP BY t1.PERSONID, t1.CARDEVENTDATE
当我运行上面的查询时,查看结果需要花费太多时间,所以它显示的错误信息是“内存中没有足够的临时空间”
在访问中可以使用任何其他方式进行此类查询。
需要查询帮助
答案 0 :(得分:1)
你的查询很乱......我不确定你打算做什么..所以这里有一些猜测,以答案的形式而不是评论..但我不能格式化评论..
因为所有联接都是左外连接..
我建议你尝试玩这个:
select FUNCTION
, PERSONID
, min(cardeventdate)
, max(cardeventdate)
from T_CARDEVENT
where FUNCTION in ('A','B','C','D')
group by FUNCTION,PERSONID
PS:在同一领域的CARDEVENTDATE和min / max组合对我来说没有多大意义。