1

We have two number plate reader cameras on the entrance and exit of the car park that will generate a CSV file when a detection takes place, which then gets automatically loaded into the database, as well as a barrier on the entrance operated automatically by the camera's "whitelist", which in turn is generated and controlled from within the database and exported into a text file.

Initially, I thought this would be a simple 3-table database as per the design below, but i am quickly realising that this is not the case:

My initial designs:

tbl_in :      ID (autonum/PK), Plate, Date_in, Time_in    
tbl_out:      ID (Autonum/PK), Plate, Date_out, Time_out    
tblwhitelist: Plate(PK), Country Code, Description

Currently,the only relationship I can think of would be:

Whitelist plate-Plate_in & plate_out where one plate in the whitelist could be seen many times within the in & out tables


This has then been made more complicated by (and this is where my brain is really melting!) the queries that have been specified (brackets show columns and basic logic am thinking of for results):

  1. "Whitelisted Vehicles on site today" (IF plate is on Whitelist: Plate, Description, Time_in,Time_out [if plate seen on OUT table today,otherwise null])
  2. "non-Whitelisted vehicles seen today" (IF plate is NOT on Whitelist: Plate, Time_in,Time_out [if plate seen on OUT table, otherwise null])
  3. "Whitelisted Vehicles time on site for today/last 7 days/last 30 days/last 90 days (IF plate on Whitelist: Plate, Description, Date_in, Time_in, Date_out, Time_out) this would have duplicate entries of same plates for multiple times on site
  4. "Non-Whitelisted vehicles time on site for today/last 7 days/last 30 days/last 90 days (IF plate not on whitelist: Plate, Date_in, Time_in, Date_out, Time_out) This Would have duplicate entries of same plates for multiple times on site

What i really need help with is some ideas on how to sort out the Query code to get these working properly. This is one of the last main hurdles for me in this project. unfortunately, it's a hurdle the size of Everest. Any help you can provide would be greatly appreciated!

4

2 回答 2

0

我同意 Straweberry 的帖子,你不需要两个表inout。你可以有一个这样的:

 tblVehicleEvent : ID (autonum/PK), Plate, EventDate, EventTime, EventType

其中 EventType 的值为INOUT

或者您可以合并 TimeIn 和 TimeOut 以及 DateIn 和 DateOut,例如:

 tblVehicleEvent : ID (autonum/PK), Plate, DateIn, DateOut, TimeIn, TimeOut

我认为稍后根据您的要求,第二个查询会更容易。

查询如下:

  1. 今天在现场列入白名单的车辆”(如果车牌在白名单上:车牌、描述、Time_in、Time_out [如果今天在 OUT 表上看到车牌,否则为空])

    SELECT W.Plate, Description, TimeIn, TimeOut FROM tblVehcileEvent V
    INNER JOIN tblWhitelist W
    ON V.Plate = W.Plate
    WHERE DateIn = curdate()

  2. “今天看到的非白名单车辆”(如果车牌不在白名单上:车牌、Time_in、Time_out [如果车牌在 OUT 表上看到,否则为空])

    SELECT Plate, TimeIn, TimeOut
    从 tblVehicleEvent
    WHERE Plate NOT IN (SELECT Plate FROM tblWhitelist)

  3. “今天/过去 7 天/过去 30 天/过去 90 天的白名单车辆在场时间(白名单上的 IF 车牌:车牌、描述、日期输入、时间输入、日期输出、超时)这将多次重复输入相同的车牌地点

    SELECT W.Plate, Description, TimeIn, TimeOut
    FROM tblVehcileEvent V
    INNER JOIN tblWhitelist W
    ON V.Plate = W.Plate
    WHERE DateIn BETWEEN startDate and EndDate

  4. “今天/过去 7 天/过去 30 天/过去 90 天的非白名单车辆在场时间(IF 车牌不在白名单上:Plate、Date_in、Time_in、Date_out、Time_out)这将多次重复输入相同车牌现场


    从 tblVehicleEvent选择板、时间输入、超时,其中板不在
    (从 tblWhitelist 中选择板)
    和日期在 startDate 和 EndDate 之间

于 2013-07-31T09:47:59.697 回答
0

就像 Strawberry 建议的那样,使用单个表,其中每条记录跟踪车辆在公园内的完整停留时间。

tbl_stay

ID (autonum/PK), Plate, Date_in, Time_in, Date_out, Time_out

如果您使用两个不同的表,则必须执行复杂的查询来关联数据。是什么告诉您 in 中的一行与 intbl_in中的另一行相关tbl_out?您必须比较车牌号并找到最接近 Date_in / Time_in 的 Date_out / Time_out ...

所以只使用一个表,但不要使用 Edper 的第一个建议,你最终会遇到同样的问题,这次根据事件类型过滤表并尝试将一行与另一行相关联。

我认为您的第一个查询看起来像这样:

SELECT *
FROM tbl_whitelisted
INNER JOIN tbl_stay
ON tbl_whitelisted.Plate = tbl_stay.Plate
WHERE tbl_stay.Date_in <= curdate()
AND (tbl_stay.Date_out IS NULL OR tbl_stay.Date_out = curdate())

第二个将是:

SELECT *
FROM tbl_stay
WHERE tbl_stay.Date_in <= curdate()
AND (tbl_stay.Date_out IS NULL OR tbl_stay.Date_out = curdate())
AND tbl_stay.Plate NOT IN (SELECT Plate FROM tbl_whitelist)

或者也许这个(今天“看到”是什么意思?我猜这意味着今天至少扫描了一次车牌,所以之前的版本不会这样做,因为它也会返回今天仍在现场的车辆,但是进来了昨天...)

SELECT *
FROM tbl_stay
WHERE (tbl_stay.Date_in = curdate() OR tbl_stay.Date_out = curdate())
AND tbl_stay.Plate NOT IN (SELECT Plate FROM tbl_whitelist)
于 2013-07-31T09:58:43.177 回答