在前台操作中得到三个表:
   领入表:
        领入时间         配件编号         领入数量
        2003-5-7          3                 100
                          4                 400
         2003-5-9         3                 47
                          6                  2345
   部门领出表:
        部门领出时间    配件编号         部门领出数量
        2003-10-9         3                 10
                          6                 400
         2003-11-7        4                 6
   个人领出表:
        个人领出时间    配件编号         个人领出数量
        2003-9-9         3                 7
                          6                 7
         2003-9-27        3                 2  现我在后台查看时得到:“关于配件编号的领入领出情况”,希望得到的界面如下    配件编号  领入时间    数量   部门领出时间   数量  个人领出时间  数量
   ---------  --------    ----   ------------   ----   -----------  ----  
(1)   3     2003-5-7  100    2003-10-9     10    2003-9-7    7
(2)         2003-5-9   47                          2003-9-27   2 我若用join连接三个表,则(2)条记录无
  若用了left join连接三个表,则会变成4条记录(1对多)
请教各位大侠:1  若用join显示如何写语句
              2  若join不行,可否还有其它方法,比如直接建个库表?
                Mshflexgrid可以显示层次结构,不知这里好用么??
                           

解决方案 »

  1.   


    select a.配件编号,a.领入时间,a.领入数量,b.部门领出时间,b.部门领出数量,c.个人领出时间,c.个人领出数量
    from 领入表 a
    left join 部门领出表 b on a.配件编号=b.配件编号
    left join 个人领出表 c on a.配件编号 = c.配件编号
    where a.配件编号 = '3'
      

  2.   

    给个思路:
    (1)得到所有单据的配件编号
      select distinct 配件编号 from 领入表 union
              select distinct 配件编号 from 个人领出表 Union
              select distinct 配件编号 from 部门领出表 union
    将结果放到mCollection 集合中 
    (2)声明三个RecordeSet(3)
    Dim Row as Long'网个行数
    Row=1
    For I=1 to mCollection.Cout
           RecordeSet(1).CommandText="Select * from 领入表 
                where 配件编号=mcollecton(I)"
           RecordeSet(2).CommandText="Select * from 部门领出表"
                where 配件编号=mcollecton(1)       
           RecordeSet(3).CommandText="Select * from 个人领出表"
                where 配件编号=mcollecton(1)       然后打开三个RecordSet
           用循环添加信息到显示界面的控件中(MSHFlexGrid为例)
           While Recordset(1).EOF=False Or RecorSet(2).EOF=False 
                     Or RecordSet(3).Eof=Fals
                  While RecordSet(1).EOF=False
                     mGrid.TextMatrix(Row,0)=Recordset(1)!配件编号
                     mgrid.Textmatrix(Row,1)=Recordset(1)!领入时间                    
                     mgrid.TextMatrix(Row,2)=Recordset(1)!领入数量
                  wend
                  While RecordSet(2).EOF=False
                     mGrid.TextMatrix(Row,3)=Recordset(2)!配件编号
                     mgrid.Textmatrix(Row,4)=Recordset(2)!领出时间                    
                     mgrid.TextMatrix(Row,5)=Recordset(2)!领出数量
                  wend
                  While RecordSet(3).EOF=False
                     mGrid.TextMatrix(Row,5)=Recordset(3)!配件编号
                     mgrid.Textmatrix(Row,6)=Recordset(3)!领出时间                    
                     mgrid.TextMatrix(Row,7)=Recordset(3)!领出数量
                  wend
                  Row=Row+1
           Wend
      next也就是用三重循环,还不明白么?我没时间,先到着
      

  3.   

    我想可以这样:
    ( 领入表 join 部门领出表)生成虚拟表   table1
    ( 领入表 join 个人领出表)生成虚拟表   table2
     table1 join table12 
      

  4.   

    select a.配件编号,a.领入时间,a.领入数量,b.部门领出时间,b.部门领出数量,c.个人领出时间,c.个人领出数量 
    from 领入表 a left join 部门领出表 b on a.配件编号=b.配件编号
                  left join 个人领出表 c on a.配件编号 = c.配件编号
    where a.配件编号 = '3'
      

  5.   


    strSql="select a.配件编号,a.领入时间,a.领入数量,b.部门领出时间,b.部门领出数量,c.个人领出时间,c.个人领出数量 
    from 领入表 a left join 部门领出表 b on a.配件编号=b.配件编号
                  left join 个人领出表 c on a.配件编号 = c.配件编号
    where a.配件编号 = '3'"rs.open strSql,cn
    set mshflexgrid.datasource=rs
    rs.close
      

  6.   

    用select 的多层查询吧! 我用过的!