我有自己写的这条sql语句。我想写的这个sql语句在postgres中。我在 oracle 中有相同的 sql 语句,它工作正常。我已经通读了语法,但对我来说它看起来不错。 oracle sql 语句如下所示:
select to_char(calldate,'Day') as Day,
trunc(calldate) as transdate,
decode(zoneorange,'-1, 'Onnet','0','Orange Uganda','1','UTL','2','MTN',3,'Airtel','4','Warid','5','MTN Fixed','Undefined') as destination
我写的postgres sql语句是这样的:
select to_char(calldate,'Day') as Day,
date_trunc('day',calldate) as transdate,
(case when zoneorange = '-1'
then 'Onnet'::text = '0'
then 'Orange Uganda' = '1'
then 'UTL' = '2'
then 'MTN' =3
then 'Airtel' = '4'
then 'Warid' = '5',
then 'MTN Fixed'
else 'Undefined' end) as destination
它提示我的 case 语句中的语法错误。在我看来没问题,所以我不知道出了什么问题。我的 postgresql 查询可能做错了什么。
最佳答案
这里有很多语法错误。
尝试:
select to_char(calldate,'Day') as Day,
date_trunc('day',calldate) as transdate,
(case zoneorange when '-1' then 'Onnet'
when '0' then 'Orange Uganda'
when '1' then 'UTL'
when '2' then 'MTN'
when '3' then 'Airtel'
when '4' then 'Warid'
when '5' then 'MTN Fixed'
else 'Undefined' end) as destination
关于sql - case 语句中 "then"处或附近的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14362770/