错误:“settlement_date”或附近的语法错误 第4行:if settlement_date> “2015年1月1日” ^ **********错误**********
错误:“settlement_date”或附近的语法错误
SQL状态:42601
性格:50
update "Recon".ship_error
set
if settlement_date > '2015-01-01'
then
shipping_fee = case
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight <= 0.5 and order_status !='return_completed' then -55
when shipping_zone = 'LOCAL' and total_weight <= 0.5 and order_status !='return_completed' then -29.4
when shipping_zone = 'ZONAL' and total_weight <= 0.5 and order_status !='return_completed' then -55
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight >= 0.5 and total_weight <= 1 and order_status !='return_completed' then -55
when shipping_zone = 'LOCAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -29.4
when shipping_zone = 'ZONAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -55
end
end
if settlement_date <= '2015-01-01'
then
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight <= 0.5 and order_status !='return_completed' then -43.4
when shipping_zone = 'LOCAL' and total_weight <= 0.5 and order_status !='return_completed' then -24.3
when shipping_zone = 'ZONAL' and total_weight <= 0.5 and order_status !='return_completed' then -43.4
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight >= 0.5 and total_weight <= 1 and order_status !='return_completed' then -86.8
when shipping_zone = 'LOCAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -58.3
when shipping_zone = 'ZONAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -86.8
end
end
from "Recon".ship_error;
或者我也试过这段代码
update "Recon".ship_error
set shipping_fee = case
when settlement_date > '2015-01-01'
then
--shipping_fee = case
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight <= 0.5 and order_status !='return_completed' then -55
when shipping_zone = 'LOCAL' and total_weight <= 0.5 and order_status !='return_completed' then -29.4
when shipping_zone = 'ZONAL' and total_weight <= 0.5 and order_status !='return_completed' then -55
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight >= 0.5 and total_weight <= 1 and order_status !='return_completed' then -55
when shipping_zone = 'LOCAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -29.4
when shipping_zone = 'ZONAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -55
end
end
when settlement_date <= '2015-01-01'
then
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight <= 0.5 and order_status !='return_completed' then -43.4
when shipping_zone = 'LOCAL' and total_weight <= 0.5 and order_status !='return_completed' then -24.3
when shipping_zone = 'ZONAL' and total_weight <= 0.5 and order_status !='return_completed' then -43.4
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight >= 0.5 and total_weight <= 1 and order_status !='return_completed' then -86.8
when shipping_zone = 'LOCAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -58.3
when shipping_zone = 'ZONAL' and total_weight >= 0.5 and total_weight <=1 order_status !='return_completed' then -86.8
end
end
from "Recon".ship_error;
答案 0 :(得分:2)
update "Recon".ship_error
set shipping_fee = case
--shipping_fee = case
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight <= 0.5 and settlement_date > '2015-01-01' and order_status !='return_completed' then -55
when shipping_zone = 'LOCAL' and total_weight <= 0.5 and settlement_date > '2015-01-01' and order_status !='return_completed' then -29.4
when shipping_zone = 'ZONAL' and total_weight <= 0.5 and settlement_date > '2015-01-01' and order_status !='return_completed' then -55
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight >= 0.5 and total_weight <= 1 and settlement_date > '2015-01-01' and order_status !='return_completed' then -55
when shipping_zone = 'LOCAL' and total_weight >= 0.5 and total_weight <=1 and settlement_date > '2015-01-01' and order_status !='return_completed' then -29.4
when shipping_zone = 'ZONAL' and total_weight >= 0.5 and total_weight <=1 and settlement_date > '2015-01-01' and order_status !='return_completed' then -55
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight <= 0.5 and settlement_date <= '2015-01-01' and order_status !='return_completed' then -43.4
when shipping_zone = 'LOCAL' and total_weight <= 0.5 and settlement_date <= '2015-01-01' and order_status !='return_completed' then -29.4
when shipping_zone = 'ZONAL' and total_weight <= 0.5 and settlement_date <= '2015-01-01' and order_status !='return_completed' then -43.4
when shipping_zone = 'NA' and order_status !='return_completed' then 0
when shipping_zone = 'NATIONAL' and total_weight >= 0.5 and total_weight <= 1 and settlement_date <= '2015-01-01' and order_status !='return_completed' then -86.8
when shipping_zone = 'LOCAL' and total_weight >= 0.5 and total_weight <=1 and settlement_date <= '2015-01-01' and order_status !='return_completed' then -58.8
when shipping_zone = 'ZONAL' and total_weight >= 0.5 and total_weight <=1 and settlement_date <= '2015-01-01' and order_status !='return_completed' then -86.8
end ;
答案 1 :(得分:0)
您的查询中有几处错误(有几次错误and
和额外的end
等)。以下是更正的查询:
UPDATE "Recon".ship_error
SET shipping_fee = CASE
WHEN settlement_date > '2015-01-01'
THEN
CASE
WHEN shipping_zone = 'NA'
AND order_status != 'return_completed'
THEN 0
WHEN shipping_zone = 'NATIONAL'
AND total_weight <= 0.5
AND order_status != 'return_completed'
THEN - 55
WHEN shipping_zone = 'LOCAL'
AND total_weight <= 0.5
AND order_status != 'return_completed'
THEN - 29.4
WHEN shipping_zone = 'ZONAL'
AND total_weight <= 0.5
AND order_status != 'return_completed'
THEN - 55
WHEN shipping_zone = 'NA'
AND order_status != 'return_completed'
THEN 0
WHEN shipping_zone = 'NATIONAL'
AND total_weight >= 0.5
AND total_weight <= 1
AND order_status != 'return_completed'
THEN - 55
WHEN shipping_zone = 'LOCAL'
AND total_weight >= 0.5
AND total_weight <= 1
AND order_status != 'return_completed'
THEN - 29.4
WHEN shipping_zone = 'ZONAL'
AND total_weight >= 0.5
AND total_weight <= 1
AND order_status != 'return_completed'
THEN - 55
END
WHEN settlement_date <= '2015-01-01'
THEN CASE
WHEN shipping_zone = 'NA'
AND order_status != 'return_completed'
THEN 0
WHEN shipping_zone = 'NATIONAL'
AND total_weight <= 0.5
AND order_status != 'return_completed'
THEN - 43.4
WHEN shipping_zone = 'LOCAL'
AND total_weight <= 0.5
AND order_status != 'return_completed'
THEN - 24.3
WHEN shipping_zone = 'ZONAL'
AND total_weight <= 0.5
AND order_status != 'return_completed'
THEN - 43.4
WHEN shipping_zone = 'NA'
AND order_status != 'return_completed'
THEN 0
WHEN shipping_zone = 'NATIONAL'
AND total_weight >= 0.5
AND total_weight <= 1
AND order_status != 'return_completed'
THEN - 86.8
WHEN shipping_zone = 'LOCAL'
AND total_weight >= 0.5
AND total_weight <= 1
AND order_status != 'return_completed'
THEN - 58.3
WHEN shipping_zone = 'ZONAL'
AND total_weight >= 0.5
AND total_weight <= 1
AND order_status != 'return_completed'
THEN - 86.8
END
END;