2013-02-03 70 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>