1表:
a       b 
数据   时间2表:
a         b           c
数据   起始时间  结束时间我想查询1表中  1.a=2.a 且1.b在2.b和2.c之间的数据select * from 1,2 where 1.a=2.a and 1.b between 2.b and 2.c我是这么写的。好像不太对高手指点啊~ 

解决方案 »

  1.   


    select t.*
    from tb1 t join tb2 e on t.a = e.a
    where t.b between e.b and e.c
      

  2.   

    我用到的3个时间都用了下convert。 这个不影响吧?
      

  3.   


    那我不接表了。用两个where in 接子查询行吗? 后边的between 用where in怎么写呀?
      

  4.   


    select *
    from tb1 t
    where exists (select 1 from tb2 where a = t.a and t.b between b and c)
      

  5.   


    select * from [1] join [2] on [1].a=[2].a and [1].b between [2].b and [2].c
      

  6.   

    select * from [1] t where exist(select 1 from  [2] where t.a=a and t.b between b and c)
      

  7.   


    select * from [1] t where exists(select 1 from  [2] where t.a=a and t.b between b and c)
      

  8.   


    select * from [1] t where exists(select 1 from  [2] where t.a=a and t.b between b and c)