PostGIS 공간쿼리 기초 연습 (1)
·
GIS/01. GIS TIL
평소 공간쿼리에 대해서 자주 사용하진 않고 필요하면 그때 그때 찾아보면서 사용했다.시간 여유가 있을 때 정리해두면 좋을 것 같아서 글로 올려본다.-> 모든 내용은 PostGIS 공식 페이지를 참조해서 작성하였습니다.https://postgis.net/workshops/postgis-intro/geometries.html 9. Geometries — Introduction to PostGIS9.1. Introduction In the previous section, we loaded a variety of data. Before we start playing with our data lets have a look at some simpler examples. In pgAdmin, once again sel..
[PostgreSQL] solvesql LV.3 폐쇄할 따릉이 정류소 찾기 2
·
프로그래밍 언어/02. SQL
https://solvesql.com/problems/find-unnecessary-station-2/ https://solvesql.com/problems/find-unnecessary-station-2/ solvesql.com🔍 문제2019년 10월 한 달 동안 따릉이 정류소에서 발생한 대여+반납 건수가 2018년 10월 한 달 동안 발생한 대여+반납 건수를 비교해서 50%미만인 정류소의 id, 이름, 자치구, 전 년 대비 비율을 출력하시요🎯정답-- 2018년 기록 합치기with m2018 as (select station_id, count(*) as cnt18from (select rent_station_id as station_idfrom rental_historywhere rent_at >=..
[PostgreSQL] solvesql LV.3 온라인 쇼핑몰의 월 별 매출액 집계
·
프로그래밍 언어/02. SQL
https://solvesql.com/problems/shoppingmall-monthly-summary/🔍 문제us e-commerce 데이터에서 연-월 별로 취소되지 않은 주문 금액의 합계, 취소된 주문 금액 합계, 전체 합계를 구하시오🎯정답select to_char(o.order_date, 'YYYY-MM') as "order_month", sum(i.price * i.quantity) filter (where o.order_id not like 'C%') as "ordered_amount", sum(i.price * i.quantity) filter (where o.order_id like 'C%') as "canceled_amount", sum(i.price * i.quantity) ..
[PostgreSQL] solvesql LV.3 할부는 몇 개월로 해드릴까요
·
프로그래밍 언어/02. SQL
https://solvesql.com/problems/installment-month/🔍 문제할부 개월 수 별로 최대 결제 금액, 최소 결제 금액, 결제 횟수, 평균 결제 금액을 구하면 되는 문제다.중요한건!!! 신용 카드로 결제한 건수!고유한 주문 건수만 봐야 한다는 것!이 두 가지 사항만 잘 확인하면 쉽게 풀 수 있었다.🎯정답select distinct(payment_installments), count(distinct(order_id)) as order_count, min(payment_value) as min_value, max(payment_value) as max_value, avg(payment_value) as avg_valuefrom olist_order_payments_da..
[PostgreSQL] solvesql LV.2 3년간 들어온 소장품 집계하기
·
프로그래밍 언어/02. SQL
https://solvesql.com/problems/summary-of-artworks-in-3-years/🔍 문제2014년~2016년도 까지 수집된 작품의 개수를 분류에 맞춰서 집계하기!🎯정답SELECT classification, count(*) filter (where to_char(acquisition_date, 'YYYY') = '2014') as "2014", count(*) filter (where to_char(acquisition_date, 'YYYY') = '2015') as "2015", count(*) filter (where to_char(acquisition_date, 'YYYY') = '2016') as "2016"from artworksgroup by classi..
[PostgreSQL] solvesql LV.2 언더스코어(_)가 포함되지 않은 데이터 찾기
·
프로그래밍 언어/02. SQL
🔍 문제https://solvesql.com/problems/data-without-underscore/🎯정답select DISTINCT(page_location)from ga-- 정규식 매칭을 사용해 '_'를 문자 그대로 인식시킨다where page_location !~ '_'order by 1❓풀이!~ 정규식 연산자를 사용해서 '_'(언더스코어)를 문자 그대로 인식시킨다.백슬래시 이스케이프가 필요한 경우 아래와 같은 방법으로 문제를 해결할 수 있다.select DISTINCT(page_location)from gawhere page_location not like '%\_%'-- 추가로 page_location에 null 값을 바꾸기 위해 아래처럼 사용해도 된다-- where coalesce(pa..