Postgrsql 使用CASE WHEN解决不定列问题

原创
2020/02/21 18:30
阅读数 357
  • CASE WHEN condition THEN column END  as name

示例如下:

SELECT WIDTH_BUCKET( public.ST_X ( geom ),107.63636363636364,114.90916363636364,10 )
grid_x,WIDTH_BUCKET( public.ST_Y ( geom ),25.454545454545457,29.090981818181824,5 )
grid_y,COUNT ( * ) count,public.ST_X(public.ST_CENTROID ( public.ST_COLLECT ( geom ) )) center_x,
public.ST_Y(public.ST_CENTROID ( public.ST_COLLECT ( geom ) )) center_y,
case when COUNT (*)<6 then ARRAY_AGG ( pk_uid ) end pk_uid 
FROM hngsmmzt.hngs_gsmm_pt 
WHERE 1=1 and geom is not null  AND
public.ST_X( geom ) BETWEEN 107.63636363636364 AND 114.90916363636364
AND  public.ST_Y( geom ) BETWEEN 25.454545454545457 AND 29.090981818181824 
AND shzt='2'  GROUP BY  grid_x,grid_y

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部