select 姓名,a.时间 as 入园时间,
       (select top 1 时间 
        from B 
        where 姓名=a.姓名 and 标记=0 and 时间>a.时间 
        order by 时间 ) as 离园时间
from 表 A,表 B
where a.标记=0
order by a.姓名,a.时间

解决方案 »

  1.   

    select 姓名,a.时间 as 入园时间,
           (select top 1 时间 
            from B 
            where 姓名=a.姓名 and 标记=1 and 时间>a.时间   --改一点
            order by 时间 ) as 离园时间
    from 表 A,表 B
    where a.标记=0
    order by a.姓名,a.时间
      

  2.   

    select 姓名,a.时间 as 入园时间,
           (select top 1 时间 
            from B 
            where 姓名=a.姓名 and 标记=1 and 时间>a.时间   --改一点
            order by 时间 ) as 离园时间
    from 表 A,表 B
    where a.标记=0
    order by a.姓名,a.时间
    -----------
    高啊!
      

  3.   

    SELECT name1, MAX(intime) AS Expr1, MAX(outtime) AS Expr2
    FROM (SELECT name1, intime = time1, outtime = NULL, item
            FROM tab1
            WHERE sts = 0
            UNION
            SELECT name1, intime = NULL, outtime = time1, item
            FROM tab1
            WHERE sts = 1) a
    GROUP BY name1, item
      

  4.   

    select 姓名,
           入园时间=(select a.时间 from tab1 a where a.A =tab1.A and a.标记 =0),
           出园时间=(select b.时间 from tab1 b where b.A =tab1.A and b.标记 =1)
    from (select 姓名 from table1 group by 姓名) tab1已经测试成功!!!
      

  5.   

    我将表结构再改一下看看:姓名   时间        接送人 标记
    -------------------------------
    A      08:00:000   AA     0
    A      09:00:000   AB     1
    A      10:00:000   AB     0
    注:  0入园  1离园
    这样子能生成这样的表吗?
    姓名  入园时间  接送人  离园时间  接送人
    -----------------------------------------
    A     08:00:000 AA      09:00:000 AB
    A     10:00:000 AB      null      null
      

  6.   

    搂主啊,要能改表结构也别改成那样的不好用
    建议:
    姓名   入园时间    接送人 离园时间       接送人
    ----------------------------------------------------
    A      08:00:000   AA     09:00:000       AB
    A      10:00:000   AB     null            null
    入园时增加一条记录如第二行,
    离园时update 表 set 离园时间= xxxx,接送人 = yyy where 姓名 = A and 离园时间 is null