1. 程式人生 > >CASE WHEN的用法 PGSQL

CASE WHEN的用法 PGSQL

select five_top,only_five, down_kind,line_road,b_id,
CASE WHEN only_five>0 THEN 1 END AS 五分以內,
CASE WHEN five_top>0 THEN 1 END AS 五分以上
 from dtinfo_breakdown_info
 

 

select dtinfo_breakdown_info.five_top,dtinfo_breakdown_info.only_five,
dtinfo_breakdown_info.down_kind,dtinfo_breakdown_info.line_road,
dtinfo_breakdown_info.service_lose,
dtinfo_breakdown_info.b_id,dtinfo_breakdown_info.down_site,dtinfo_down_site."name" as 故障地點,
CASE WHEN dtinfo_breakdown_info.only_five>0 THEN 1 ELSE 0 END AS 五分以內,
CASE WHEN dtinfo_breakdown_info.five_top>0 THEN 1 ELSE 0 END AS 五分以上,
CASE WHEN dtinfo_breakdown_info.delay_time>0 THEN 1 ELSE 0 END AS 晚點
 from dtinfo_breakdown_info,dtinfo_down_site
where dtinfo_down_site."id"=dtinfo_breakdown_info.down_site