select 姓名,类别,金额,出勤天数,缺勤天数 from 资料表,类别表,出勤表,缺勤表
where 资料表.代码=出勤表.代码 and 资料表.类别=类别表.类别 
     and 资料表.代码=出勤表.代码 and 缺勤表.代码=资料表.代码

解决方案 »

  1.   

    最基本的主外键连接,注意写明属主。见下面所示:select a.代码, a.姓名,a.类别,b.金额,c.出勤天数,d.缺勤天数 
    from 资料表 a,类别表 b,出勤表 c,缺勤表 d
    where  a.代码 = c.代码 and 
           a.代码 = d.代码 and
           a.类别 = b.类别
      

  2.   

    SELECT 资料表.代码   资料表.姓名    资料表.类别  类别表.金额  出勤表.出勤天数  缺勤表.缺勤天数 FROM  资料表 INNER JOIN 类别表 ON 类别表.类别 =  资料表.类别 INNER
    JOIN 出勤表 ON 出勤表.代码 = 资料表.代码 INNER JOIN 缺勤表.代码 = 资料表.代码
      

  3.   

    不行呀   记录不完整。  是不是要用 full join 等其它的连接,,才能达到上述效果
      

  4.   

    不过我把你的语句改了一下,  就行了.SELECT 资料表.代码   资料表.姓名    资料表.类别  类别表.金额  出勤表.出勤天数  缺勤表.缺勤天数 FROM  资料表 FULL JOIN 类别表 ON 类别表.类别 =  资料表.类别 FULL
    JOIN 出勤表 ON 出勤表.代码 = 资料表.代码 FULL JOIN 缺勤表.代码 = 资料表.代码谢谢你,,给分!
      

  5.   

    select *
    ,金额=(select sum(金额) from 类别表 where 类别=a.类别)
    ,出勤天数=isnull((select sum(出勤天数) from 出勤表 where 代码=a.代码),0)
    ,缺勤天数=isnull((select sum(缺勤天数) from 缺勤表 where 代码=a.代码),0)
    from 资料表 a
      

  6.   

    select *
    ,金额=(select sum(金额) from 类别表 where 类别=a.类别)
    ,出勤天数=isnull((select sum(出勤天数) from 出勤表 where 代码=a.代码),0)
    ,缺勤天数=isnull((select sum(缺勤天数) from 缺勤表 where 代码=a.代码),0)
    from 资料表 a
      

  7.   


    select a.*, 
           isnull(金额,0) 金额, 
           isnull(出勤天数,0) 出勤天数, 
           isnull(缺勤天数,0) 缺勤天数
    from 资料表 a left join 类别表 b on a.代码=b.代码
                  left join 出勤表 c on a.代码=c.代码
                  left join 缺勤表 d on a.代码=d.代码