0

我正在使用 RFID 技术在 VS2010 中制作考勤管理系统,在 SQL Server 2005 中进行所有后端数据操作,我知道基本的 SQL,但我需要一些帮助来解决这个问题。

我有以下表格:

教师主数据

fname
fid
dept
title
phone
dob

计时

fname
fid
intime_a
outtime_d
lunchout_b
lunchin_c

原始转储

fid
timecode
currtime

这里的数据是从我在 vb.net 中编写的串行端口数据记录器程序中保存的,fid 是 RFID 标签 ID,时间码是 A、B、C 或 D(用于识别时间为 intime-A、lunchout-B、lunchin-C , outtime-D) 和 currtime 是当前系统时间。我通过一个微控制器获取 RFID 标签 ID,该微控制器根据物理按钮按下添加时间码。

我需要做的是根据时间码对所有数据进行排序rawdumps并复制到其中。timings时间码为“A”的字段被保存到时间字段fid中。以及对应的from 。currtimerawdumpsintime_afnamefacultymasterdatafid

任何信息帮助将不胜感激。

非常感谢。

4

3 回答 3

0

I got the solution, someone helped me out, what I needed to do was convert a column into rows while sorting it. I needed to use cross tabs.

This is what I needed to do:

SELECT F.fName, F.fID, 
MIN(CASE WHEN R.TimeCode = 'A' THEN CurrTime END) AS Intime_a,
MAX(CASE WHEN R.TimeCode = 'D' THEN CurrTime END) AS outtime_d,
MIN(CASE WHEN R.TimeCode = 'B' THEN CurrTime END) AS LunchOut_b,
MAX(CASE WHEN R.TimeCode = 'C' THEN CurrTime END) AS LunchIn_c
FROM dbo.facultymasterdata F LEFT JOIN dbo.rawdumps R ON F.fid = R.fid 
GROUP BY F.fid, F.fname 
于 2012-04-21T05:58:08.110 回答
0

我不确定您对 [fid] 和 [curtime] 字段的含义有代码“A”并保存在 [intime_a] 中。这是一笔钱吗?

这应该让你走上正确的轨道。

INSERT INTO timings(fname,fid,intime_a)
    SELECT a.fname, b.fid, b.curtime
    FROM facultymasterdata a, rawdumps b 
    WHERE a.fid = b.fid
    ORDER BY b.timecode;

编辑:在阅读您对问题的编辑和评论回复后,我会编写一个触发器来处理此插入。

于 2012-04-20T08:03:15.097 回答
0

我可能会使用联合选择,导致像这样的大讨厌插入

insert into timings
(fname,fid,intime_a,lunchout_b,lunchin_c, outtime_d)
select
    f.fname,
    f.fid,
    r.intime_a,
    r.lunchout_b,
    r.lunchin_c,
    r.outtime_d,
from
    facultymasterdata as f
inner join (
    select
        fid as fid,
        currtime as currtime,
        currtime as intime_a,
        null as lunchout_b,
        null as lunchin_c,
        null as outtime_d,
    from
        rawdumps
    where timecode = 'A'
    union select
        fid as fid,
        currtime as currtime,
        null as intime_a,
        currtime as lunchout_b,
        null as lunchin_c,
        null as outtime_d,
    from
        rawdumps
    where timecode = 'B'
    union select
        fid as fid,
        currtime as currtime,
        null as intime_a,
        null as lunchout_b,
        currtime as lunchin_c,
        null as outtime_d,
    from
        rawdumps
    where timecode = 'C'
    union select
        fid as fid,
        currtime as currtime,
        null as intime_a,
        null as lunchout_b,
        null as lunchin_c,
        currtime as outtime_d,
    from
        rawdumps
    where timecode = 'D'
    ) r on r.fid = f.fid
order by r.currtime
于 2012-04-20T08:14:00.617 回答