(SELECT count(id) FROM logpm_distribution_bill_lading_scan ldbls WHERE ldbls.stock_list_id = lddd.stock_list_id and ldbls.material_type = 1) AS pick_up_quantity,
CASE
WHEN (lddd.quantity - (SELECT count(id) FROM logpm_distribution_bill_lading_scan ldbls WHERE ldbls.stock_list_id = lddd.stock_list_id and ldbls.material_type = 1)) > 0 THEN 20
WHEN (lddd.quantity - (SELECT count(id) FROM logpm_distribution_bill_lading_scan ldbls WHERE ldbls.stock_list_id = lddd.stock_list_id and ldbls.material_type = 1)) = 0 THEN 10
WHEN ( SELECT count( id ) FROM logpm_distribution_bill_lading_scan ldbls WHERE ldbls.stock_list_id = lddd.stock_list_id AND ldbls.material_type = 1 ) = 0 THEN
'待提货'
WHEN lddd.quantity - ( SELECT count( id ) FROM logpm_distribution_bill_lading_scan ldbls WHERE ldbls.stock_list_id = lddd.stock_list_id AND ldbls.material_type = 1 ) > 0 THEN
'提货中'
WHEN lddd.quantity - ( SELECT count( id ) FROM logpm_distribution_bill_lading_scan ldbls WHERE ldbls.stock_list_id = lddd.stock_list_id AND ldbls.material_type = 1 ) = 0 THEN
'已提货'
END AS pickupStatusName,
CASE
WHEN ( SELECT count( id ) FROM logpm_distribution_bill_lading_scan ldbls WHERE ldbls.stock_list_id = lddd.stock_list_id AND ldbls.material_type = 1 ) = 0 THEN
10
WHEN lddd.quantity - ( SELECT count( id ) FROM logpm_distribution_bill_lading_scan ldbls WHERE ldbls.stock_list_id = lddd.stock_list_id AND ldbls.material_type = 1 ) > 0 THEN
20
WHEN lddd.quantity - ( SELECT count( id ) FROM logpm_distribution_bill_lading_scan ldbls WHERE ldbls.stock_list_id = lddd.stock_list_id AND ldbls.material_type = 1 ) = 0 THEN
30
END AS pickup_status
from logpm_distribution_delivery_details lddd
LEFT JOIN logpm_distribution_stock_list ldsl on lddd.stock_list_id = ldsl.id
(select COUNT(id) from logpm_distribution_bill_lading_scan
where stock_article_id = ldsa.id ) pick_up_quantity,
CASE
WHEN (SELECT COUNT(id) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id) - (SELECT COUNT(id) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3)) = 0 THEN 20
WHEN (SELECT COUNT(id) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id) - (SELECT COUNT(id) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3)) > 0 THEN 10
WHEN (SELECT COUNT(id) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id) - (SELECT COUNT(id) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3)) < 0 THEN 30
WHEN ( SELECT count( id ) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id ) = 0 THEN 10
WHEN ( SELECT count( id ) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id ) - ( SELECT count( id ) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN ( 1, 3 ) ) < 0 THEN 20
WHEN ( SELECT count( id ) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id ) - ( SELECT count( id ) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3)) = 0 THEN 30