WITH center AS ( SELECT ST_SetSRID(ST_Point(126.94130, 37.42187), 4326) as point ) SELECT point from center
거리를 비교
1 2 3 4 5 6
WITH center AS ( SELECT ST_SetSRID(ST_Point(126.94130, 37.42187), 4326) as geom ), dist AS ( SELECT ST_Distance(ST_Centroid(geom), (SELECT geom FROM center)) as dist, *FROM my_table where my_column like'%대림%' ) SELECT*FROM dist
정렬을 추가
1 2 3 4 5 6 7 8
WITH center AS ( SELECT ST_SetSRID(ST_Point(126.94130, 37.42187), 4326) as geom ), dist AS ( SELECT ST_Distance(ST_Centroid(geom), (SELECT geom FROM center)) as dist, *FROM my_table where my_column like'%대림%' ), dist_order AS ( SELECT*FROM dist orderby dist.dist asc ) SELECT*FROM dist_order
페이징 추가
1 2 3 4 5 6 7 8
WITH center AS ( SELECT ST_SetSRID(ST_Point(126.94130, 37.42187), 4326) as geom ), dist AS ( SELECT ST_Distance(ST_Centroid(geom), (SELECT geom FROM center)) as dist, *FROM my_table where my_column like'%대림%' ), dist_order AS ( SELECT*FROM dist orderby dist.dist asc limit 10offset (3-1) *10 ) SELECT*FROM dist_order
마이바티스로 변경
변수 목록
#{text}
#{x}
#{y}
#{page}
#{row_count}
1 2 3 4 5 6 7 8 9 10 11
<select id="listCnt" resultType="int"> <bind name="pattern" value="'%' + text + '%'" /> WITH center AS ( SELECT ST_SetSRID(ST_Point(CAST(#{x} asdouble precision), CAST(#{y} asdouble precision)), 4326) as geom ), list AS ( SELECT ST_Distance(ST_Centroid(geom), (SELECT geom FROM center)) as dist, *FROM my_table where my_column like #{pattern} ), list_order AS ( SELECT*FROM dist orderby list.dist asc limit #{row_count} offset (#{page} -1) * #{row_count} ) SELECT*FROM list_order </select>
총 수를 구하는 쿼리
1 2 3 4
<selectid="listCnt"resultType="int"> <bindname="pattern"value="'%' + text + '%'" /> SELECT count(*) as count FROM my_table where my_column like #{pattern} </select>
에러
The column index is out of range: 1, number of columns: 0.