运行环境是firebrid 。sql基本跟sqlserver差不多,就是不能用sqlserver里面的convert 还有一些忘记了(日期转换函数),
----------------------------------------------------
现在我有一个表 att_unattinfo(出勤信息表)
字段有 att_ID (ID),att_DID(员工编号),att_ddate(上班日期),att_am_late(上午迟到分钟数),att_pm_late(下午迟到分钟数),att_tm_late(总迟到分钟数),att_am_early(上午早退分钟数),att_pm_early(下午早退分钟数),att_tm_early(总迟到分钟数)
-------------
另外一个表sta_information(员工基本信息表)
字段有 att_ID(员工ID),att_name(员工姓名)
-------------
还有一个表att_unattinfo(非正常出勤信息表)
字段有att_usid(员工ID),att_uname(员工姓名),att_udate(上班日期),att_amtype(上午出勤情况[旷工,带薪假,非带薪假]),att_pmtype(下午出勤情况[旷工,带薪假,非带薪假]),
===================================================================================
根据上面的表的信息,组合一个新表,这个新表的数据是根据上面2个表的内容插入的。一个月份每日的统计信息字段。
att_porttotal (出勤统计表)
字段有:att_ptid(ID),att_ptstaname(员工姓名),att_ptm1(1号),att_ptm2(2号),att_ptm3(3号).......att_pm29(29号),att_pm30(30号),att_pm31(31号),
att_Dtday(出勤天数),att_ptattdance(出勤率),att_ptsituation(出勤情况[分上下午,上午为0,下午为1]) 
备注:
在表att_unattinfo(出勤信息表) 中如果在2009-01-01号 att_am_late(上午迟到分钟数)>0 则 在att_porttotal (出勤统计表) 的出勤为迟到。
如果那号为旷工,则为旷工。迟到早退算出勤。非带薪假与带薪假,旷工,不算出勤。出勤天数 每一次正常或早退,迟到出勤算0.5天。旷工,非带薪假,带薪假出勤算0天。
att_ptattdance 出勤率是那本月的出勤天数/本月总天数。显示的效果如下:(测试数据而已)
att_ptid    att_ptstaname ,att_ptm1,att_ptm2,att_ptm3...........att_ptm29,att_ptm30,att_ptm31,att_dtday,att_ptattdance,att_ptsituation
  1            apple        迟到      正常       早退                  正常       迟到        早退        15.5      0.5             0
  2            apple        正常      旷工       迟到                  正常       早退        请假        12        0.4             1

解决方案 »

  1.   

    先晕一下,楼主辛苦了,现在只是抽空上一下CSDN,看看哪位长期潜水的帮你解决一下吧
      

  2.   

    三表inner join 根据 att_ptid ,然后应该有函数可以判断符合什么条件是迟到   
      

  3.   

    其实思路我还是有的,跟你的差不错吧。
    我写不出sql语句。。
    求助啊
      

  4.   

    如果员工A迟到,早退,旷工这三种情况都有,怎么弄?
    可以参照下边的结构设计,在此基础上加统计就可以出来你要的数据的纵向显示,然后再列转行即可--建议把'出勤信息表'和'非正常出勤信息表'合并
    create table #att_type(ID int, Scrp varchar(10))
    insert into #att_type select 1, '出勤'
    insert into #att_type select 2, '旷工'
    insert into #att_type select 3, '带薪假'
    insert into #att_type select 4, '非带薪假'create table #att_attinfo(att_ID INT,att_DID INT,att_ddate DATETIME,att_am_late INT,att_pm_late INT,
    att_tm_late INT,att_am_early INT,att_pm_early INT,att_tm_early INT, att_amtype INT,att_pmtype INT) 
    INSERT INTO #att_attinfo SELECT 1, 11, '2009-01-14', 0, 2, 2, 3, 0, 3, 1, 1
    INSERT INTO #att_attinfo SELECT 2, 12, '2009-01-14', 2, 2, 4, 3, 5, 8, 1, 1
    INSERT INTO #att_attinfo SELECT 3, 11, '2009-01-15', 2, 2, 4, 3, 5, 8, 1, 1
    INSERT INTO #att_attinfo SELECT 4, 12, '2009-01-15', 0, 0, 0, 0, 0, 0, 3, 2
    INSERT INTO #att_attinfo SELECT 5, 11, '2009-01-16', 0, 0, 0, 3, 7, 10, 4, 1--例
    select B.att_ID, B.att_DID,att_ddate,att_am_late,att_pm_late,att_tm_late,att_am_early,att_pm_early,att_tm_early, c.scrp, d.scrp
    from #sta_information A 
    left join #att_attinfo B on a.att_ID = b.att_DID
    left join #att_type C on b.att_amtype = c.ID
    left join #att_type D on b.att_pmtype = D.ID
      

  5.   

    att_ID      att_DID     att_ddate               att_am_late att_pm_late att_tm_late att_am_early att_pm_early att_tm_early scrp       scrp
    ----------- ----------- ----------------------- ----------- ----------- ----------- ------------ ------------ ------------ ---------- ----------
    1           11          2009-01-14 00:00:00.000 0           2           2           3            0            3            出勤         出勤
    3           11          2009-01-15 00:00:00.000 2           2           4           3            5            8            出勤         出勤
    5           11          2009-01-16 00:00:00.000 0           0           0           3            7            10           非带薪假       出勤
    2           12          2009-01-14 00:00:00.000 2           2           4           3            5            8            出勤         出勤
    4           12          2009-01-15 00:00:00.000 0           0           0           0            0            0            带薪假        旷工(5 行受影响)