我有一个名为batch
batch_id unit_size product_id
2 100000 c001
3 30000 t008
另一个名为batch_process
batch_id process_id status
2 100000 0
2 100000 1
2 100000 2
2 100000 1
3 30000 2
3 30000 2
3 30000 2
3 30000 2
现在我想获得输出3
AS batch_id
表单batch
表格,因为在batch_process
表中,process_id
状态2
的{{1}}状态为batch_id = 3
{1}}
如何选择它。
答案 0 :(得分:0)
此查询可能会帮助您
SELECT batch1.batch_id,batch_process1.process_id
FROM batch_process AS batch_process1,
batch AS batch1
WHERE batch1.batch_id = batch_process1.batch_id
AND batch_process1.status=2
答案 1 :(得分:0)
如果您只想选择状态为2的batch_id,那么您只需编写:
select distinct batch_id from batch_process where status=2
但是如果你想从批处理表中查询信息,不仅要查询batch_id,你可以写:
SELECT batch.batch_id,
batch.unit_size,
batch.product_id
LEFT JOIN batch_process ON batch.batch_id=batch_process.batch_id
WHERE batch_process.status=2