如果是在Mysql Update中查询

时间:2016-02-06 06:15:29

标签: mysql

我需要一个查询来根据另一个字段的计数更新表中的某些字段。

Update 
    bank_sample_map 
LEFT JOIN 
    sample_details ON bank_sample_map.sample_track_id = sample_details.sampletrack_id 
LEFT JOIN 
    order_details ON order_details.sample_detail_id = sample_details.sample_id 
LEFT JOIN 
    test_details ON test_details.test_detail_id = order_details.test_detail_id
SET 
    bank_sample_map.sample_id = sample_details.sample_id, bank_sample_map.order_id = order_details.order_number,
bank_sample_map.testid = test_details.test_id,bank_sample_map.test_cost = test_details.test_cost

WHERE 
    bank_sample_map.sample_id IS NULL 
    AND bank_sample_map.order_id IS NULL 
    AND bank_sample_map.testid IS NULL 
    AND (select count(order_number) < 2  from order_details where sample_detail_id = sample_details.sample_id);

if(count(order_number)&lt; 2)我需要更新sample_id,order_id,testid,test_cost 否则只更新sample_id。

如何更改我的查询以满足此条件。

0 个答案:

没有答案