2013-02-03 65 views
1

我有一个表,它看起来像:MySQL的SELECT查询与条件

id batch_id start_ts stop_ts 

我要选择那些昨天开始IDS(可以通过给start_ts轻松完成> ..和start_ts < ..)并在表中使用与此id的batch_id相同的batch_id,并且该id在昨天结束。

什么是构建这个MySQL查询的好方法?

回答

2

怎样......

select <field list> 
from table t1 
join table t2 on t1.id = t2.batch_id 
where start_ts between <date 1> and <date 2>