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