如图所示表结构:结构关系:
org.lineId=emp.lineId
emp.empId=ot.empId求适用于MySQL SQL 语句实现:
查询ot 表信息,按照org 的flowid 分类

解决方案 »

  1.   

    补充问题:如何实现,ot 表中的empid + dateId 的唯一性,即确定每个empId 在一个dateId 只能录入一条信息?
      

  2.   


    利用unique 索引create UNIQUE INDEX uq_ot_empid_dateId on ot(empid,dateId);也可以直接在create table 时的SQL语句中加入。
      

  3.   


    看不到图,猜一下了。
    各flowid的加班明细
    select org.flowid,ot.*
    from ot,emp,org
    where org.lineId=emp.lineId
    and emp.empId=ot.empId
    order by org.flowid或者加班汇总
    select org.flowid,sum(ot.hours)
    from ot,emp,org
    where org.lineId=emp.lineId
    and emp.empId=ot.empId
    group by org.flowid
    order by org.flowid