簡體   English   中英

如何在 Oracle 數據庫中的單個列中連接 case 語句值的值

[英]How to concat the values of case statement values in a single column in Oracle database

select
 case
   when s.X344731='Y' then 'Property Tax Assessment'
   when s.X344732='Y' then 'Property Tax Payment'
   when s.X344733='Y' then 'Birth and Death Certificate'
   when s.X344734='Y' then ' Trade License'
   when s.X344735='Y' then ' Complaints/Grievance Redressal'
   when s.X344736='Y' then 'Water Connection'
   when s.X344737='Y' then 'Sewerage Connection'
   when s.X344738='Y' then 'Online Building Plan Approval System'    
   when s.X344739='Y' then ' Fire NOC'    
   when s.X3447310='Y' then ' NOC (Others)'    
   when s.X3447311='Y' then 'Certificates (Others)'    
   when s.X3447312='Y' then 'User Charges (water charges, parking fee, advertisement charges, electricity charges etc. )'    
   when s.X3447313='Y' then 'All of the above'    
   when s.X3447314='Y' then 'None of the above'    
   else 'Not Answered' end as municipal_services_do_you_use    
from lime_survey_988773 s 
left join lime_tokens_988773 t 
on (s.token=t.token)     
where s.submitdate is not null 
  and user_id=143561; 

我想將這三個“財產稅評估”、“財產稅支付”和“出生和死亡證明”的值結合起來,它看起來像這樣:-

User_id  Municipal_Services_Do_you_use                                                      State
142351   ('Property Tax Assessment', 'Property Tax Payment','Birth and Death Certificate')  Delhi

您可以將條件聚合與連接運算符 ( || ) 結合使用,例如

SELECT user_id AS "User_id",
       MAX(CASE WHEN s.X344731='Y' THEN '(''Property Tax Assessment''' END)||
       MAX(CASE WHEN s.X344732='Y' THEN ',''Property Tax Payment''' END)||
       MAX(CASE WHEN s.X344732='Y' THEN ',''Birth and Death Certificate'')' END) 
       AS "Municipal_Services_Do_you_use"     
  FROM lime_survey_988773 s 
  LEFT JOIN lime_tokens_988773 t 
    ON t.token = s.token  
 WHERE user_id = 143561 
 GROUP BY user_id

將返回所需的結果,前提是在加入這些表后,對於名稱為X344...user_id = 143561的每一列返回至少一個'Y'值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM