我有两个表,DATA
并且EVENTS
,具有以下数据:
EVENTS
EventIndex ObjID LocID EventData EventTime EventType
83707365 3519434 10376 0 2013-05-19 11:32:11 137
83707849 3519434 10374 0 2013-05-19 11:35:18 137
83714233 888799 10376 0 2013-05-19 12:24:45 137
83715200 888799 10184 0 2013-05-19 12:32:18 137
DATA
EventIndex TagName TagValue
83714233 ObjName Peter
83714233 LocName H118
83715200 ObjName Peter
83715200 LocName H116
83707365 ObjName John
83707365 LocName H118
83707849 ObjName John
83707849 LocName H116
我从哪里开始使用 SQL SQLLite 查询?
我想得到结果:
Name Location Entry Exit Total
Peter H118 12:24:45 12:32:18 00:07:33
John H118 11:32:11 11:35:18 00:03:07
嗨meewoK,可以给出以下情况:
名称 位置 入口 出口 总计
Peter H118 12:24:45 12:32:18 00:07:33
John H118 11:32:11 11:35:18 00:03:07
John H118 11:44:52 11:45: 27 00:00:35
约翰 H118 12:31:15 12:32:46 00:01:31
我正在尝试修改您的查询,但找不到解决方案。谢谢
此代码适用于 SQL SERVER:
SELECT E.EventIndex, N.tagvalue AS Name, L.tagvalue AS Location, E.eventtime AS Entry, NEV.[Exit]
FROM
[EVENTS] E
INNER JOIN [DATA] N ON E.EventIndex = N.eventindex AND N。 tagname = 'ObjName'
INNER JOIN [DATA] L ON E.EventIndex = L.eventindex AND L.tagname = 'LocName' 外部
应用(
SELECT TOP (1) NE.eventtime AS [Exit]
FROM
[EVENTS] NE
INNER JOIN [数据] NL ON NE.EventIndex = NL.eventindex AND NL.tagname = 'ObjName'
WHERE
NE.EventIndex > E.EventIndex
AND NL.tagvalue = N.tagvalue
ORDER BY
NE.EventIndex
) NEV
WHERE L.tagvalue = 'H118'
有人可以帮我把它传递给 SQLite 吗?谢谢