我有这个我写的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查询中可能出错了什么。
答案 0 :(得分:4)
这里有很多语法错误。
尝试:
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