求一句sql
表A
id time
1 2009-01-01
2 2009-02-01
3 2009-03-01
表B
id time text
1 2009-01-01 111
2 2009-01-01 222
3 2009-01-01 333
4 2009-02-02 444
现要根据 表A的id选出datediff(day,表A.time,表B.time)=0 条件下表B的所有内容
1、条件为利用表A的id
自己写的:
select * from 表B where datediff(day,time,(select time from 表a where id=@id))=0
这样对不对?
[解决办法]
select * from 表B a inner join 表a a on datediff(day,a.time.b.time)=0 and id=@id
[解决办法]
另外你直接比较日期不就行了?
- SQL code
select * from 表B , 表a where 表a.time=表b.timeand id=@id