下面有两个表分别查询出对应x的一天内的数据:表1.
x    xx
1    a
2    aa
3    aaa表2.
y          time              yy
2    2009-12-01 08:20:33      0
1    2009-12-01 10:22:43      1
1    2009-12-01 11:18:30      0
3    2009-12-01 15:41:25      0
2    2009-12-02 17:52:33      1
3    2009-12-02 19:27:13      0
2    2009-12-02 20:39:05      1
2    2009-12-02 21:18:05      0我想得到的数据:x     xx         time                 yy
2     aa     2009-12-02 17:20:33      1
2     aa     2009-12-02 20:39:05      1
2     aa     2009-12-02 20:18:05      0请问用一条语句如何得出上面的结果  先谢谢了

解决方案 »

  1.   

    select 表1.x,表1.xx,表2.time,表2.yy 
    from 表1 join 表2 on 表1.x=表2.y
    where 表1.x=2
      

  2.   

    1楼有点误,应该是
    select 表1.x,表1.xx,表2.time,表2.yy 
    from 表1 join 表2 on 表1.x=表2.y 
    where 表1.x=2 and 表1.xx='aa'
      

  3.   

    不是koukoujiayi那样啊  我需要的是一天内的数据  只要  x=2的  2009-12-02 的数据  1号数据不要
      

  4.   

    select 表1.x,表1.xx,表2.time,表2.yy from 表1 right join 表2 on 表1.x=表2.y ground by 表1.x
    这样不知道可以不?
      

  5.   

    select 表1.x,表1.xx,表2.time,表2.yy 
    from 表1 join 表2 on 表1.x=表2.y 
    where 表1.x=2 and 表2.time between '2009-12-02' and '2009-12-02 23:59:59'
      

  6.   

    between '2009-12-02 00:00:00' and '2009-12-02 23:59:59'