값 그룹화 및 다시 코딩하기
evanston311.category에는 거의 150개의 서로 다른 값이 있습니다. 하지만 일부 범주는 "Main Category - Details" 형태로 서로 비슷합니다. 주요 범주로 집계하면 어떤 요청이 흔한지 더 잘 파악할 수 있어요.
이를 위해, 서로 다른 category 값을 새로운 standardized 값에 매핑하는 임시 테이블 recode를 만드세요. standardized 값은 대시('-') 앞의 범주 부분이 되도록 하세요. 이 값은 split_part() 함수로 추출합니다:
split_part(string text, delimiter text, field int)
이 패턴에 맞지 않는 몇 가지 경우를 추가로 정리할 필요도 있습니다.
그런 다음 evanston311 테이블을 recode와 조인하여 새 standardized 범주 값별로 요청을 그룹화할 수 있습니다.
이 연습은 강의의 일부입니다
SQL로 하는 탐색적 데이터 분석
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
-- Fill in the command below with the name of the temp table
DROP TABLE IF EXISTS ___;
-- Create and name the temporary table
CREATE ___ ___ ___ AS
-- Write the select query to generate the table with distinct values of category and standardized values
SELECT DISTINCT category,
___(___(___, ___, ___)) AS standardized
-- What table are you selecting the above values from?
FROM ___;
-- Look at a few values before the next step
SELECT DISTINCT standardized
FROM recode
WHERE standardized LIKE 'Trash%Cart'
OR standardized LIKE 'Snow%Removal%';