Sql if条件下的Postgres语法错误
我试图计算佣金,根据佣金值(佣金),我想更新列值fixed_feeSql if条件下的Postgres语法错误,sql,postgresql,postgresql-9.2,Sql,Postgresql,Postgresql 9.2,我试图计算佣金,根据佣金值(佣金),我想更新列值fixed_fee select st1.* ,(st1.order_item_value * st1.commission_rate)/100 commiss , if commiss < 50 then update payment_error set fixed_fee = -5 where commiss <= 50 else if commiss >= 50 then update payme
select st1.* ,(st1.order_item_value * st1.commission_rate)/100 commiss ,
if commiss < 50 then
update payment_error set fixed_fee = -5 where commiss <= 50
else if commiss >= 50 then
update payment_error set fixed_fee = -10 where commiss >=50
else
end if
from payment_error as st1 join payment_error as st2 on st1.order_item_id=st2.order_item_id ;
选择st1.*(st1.订单\项目\价值*st1.佣金\费率)/100佣金,
如果佣金<50,则
更新付款错误集固定费用=-5,其中佣金=50,然后
更新付款错误集固定费用=-10,其中佣金>=50
其他的
如果结束
从付款错误作为st1将付款错误作为st2加入st1。订单项目id=st2。订单项目id;
运行时出现的错误是:
ERROR: syntax error at or near "<"
LINE 2: if commiss<50 then
^
********** Error **********
ERROR: syntax error at or near "<"
SQL state: 42601
Character: 87
ERROR:syntax ERROR位于或靠近“您不能同时使用update和select。要更新,您可以尝试以下操作:
update payment_error
set fixed_fee = case when (order_item_value * commission_rate * .01) < 50 then -5
else 5 --In your case you have use both as -5 so change it as per your reqm
更新付款\u错误
设置固定费用=当(订单项目价值*佣金率*0.01)<50然后-5时的情况
else 5——在您的情况下,您将两者都用作-5,因此请根据您的需求进行更改
您不能同时使用“更新”和“选择”。要更新,您可以尝试以下操作:
update payment_error
set fixed_fee = case when (order_item_value * commission_rate * .01) < 50 then -5
else 5 --In your case you have use both as -5 so change it as per your reqm
更新付款\u错误
设置固定费用=当(订单项目价值*佣金率*0.01)<50然后-5时的情况
else 5——在您的情况下,您将两者都用作-5,因此请根据您的需求进行更改
在SQL中不能使用if
。这仅在PL/pgSQL等过程语言中可用
但更重要的是,不能将update
语句嵌入select
语句中
您可以使用一个CASE
,通过一个UPDATE
语句来完成您要做的事情:
update payment_error
set fixed_fee = case
when (order_item_value * commission_rate)/100 <= 50 then -5
else 5 --<<< different value here
end;
更新付款\u错误
设置固定费用=案例
当(订单项目价值*佣金率)/100时,您不能在SQL中使用if
。这仅在PL/pgSQL等过程语言中可用
但更重要的是,不能将update
语句嵌入select
语句中
您可以使用一个CASE
,通过一个UPDATE
语句来完成您要做的事情:
update payment_error
set fixed_fee = case
when (order_item_value * commission_rate)/100 <= 50 then -5
else 5 --<<< different value here
end;
更新付款\u错误
设置固定费用=案例
何时(订单项目价值*佣金率)/100您的语句无效,无法识别。您必须准确解释作业并提供表定义,然后任何人才能在不做许多假设的情况下将其正确转换为有效的SQL。除了无效语法ele之外,还存在空值、舍入错误、重叠范围、行重复等缺陷声明。令人震惊的是,在如此小的一段SQL中会出现如此多的模糊性。您的声明是无效的,无法识别。您必须准确地解释作业并提供表定义,然后任何人才能正确地将其转换为有效的SQL,而无需做出许多假设。存在空值、舍入错误和重叠的陷阱除了无效的语法元素之外,ping范围、行重复等等。在如此小的一段SQL中,模糊程度之高令人震惊。