Question 1. Docker ์ฒซ ์คํ ์ดํดํ๊ธฐ
Run docker with the python:3.12.8 image in an interactive mode, use the entrypoint bash.
์ด ์ด๋ฏธ์ง์์ pip์ ๋ฒ์ ์ ๋ฌด์์ธ๊ฐ์?
24.3.1- 24.2.1
- 23.3.1
- 23.2.1
Question 2. Docker ๋คํธ์ํน๊ณผ docker-compose ์ดํดํ๊ธฐ
๋ค์ docker-compose.yaml์ด ์ฃผ์ด์ก์ ๋, pgadmin์ด postgres ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ฐ๊ฒฐํ๊ธฐ ์ํด ์ฌ์ฉํด์ผ ํ๋ hostname๊ณผ port๋ ๋ฌด์์ธ๊ฐ์?
services:
**db**:
container_name: **postgres**
image: postgres:17-alpine
environment:
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'postgres'
POSTGRES_DB: 'ny_taxi'
ports:
- **'5433:5432'**
volumes:
- vol-pgdata:/var/lib/postgresql/data
pgadmin:
**container_name: pgadmin**
image: dpage/pgadmin4:latest
environment:
PGADMIN_DEFAULT_EMAIL: "pgadmin@pgadmin.com"
PGADMIN_DEFAULT_PASSWORD: "pgadmin"
**ports:
- "8080:80"**
volumes:
- vol-pgadmin_data:/var/lib/pgadmin
volumes:
vol-pgdata:
name: vol-pgdata
vol-pgadmin_data:
name: vol-pgadmin_data- postgres:5433
- localhost:5432
- db:5433
postgres:5432db:5432
Question 3. ์ดํ ๊ตฌ๊ฐ ์
**2019๋ 10์ 1์ผ(ํฌํจ)๋ถํฐ 2019๋ 11์ 1์ผ(์ ์ธ)**๊น์ง ๊ธฐ๊ฐ ๋์, ๊ฐ๊ฐ ๋ค์๊ณผ ๊ฐ์ ์ดํ์ด ๋ช ๋ฒ ์์๋์:
-- 1. ์ค๋ณต ์ฒดํฌ
SELECT
COUNT(*) AS cnt
FROM green_tripdata
GROUP BY
"VendorID", "lpep_pickup_datetime",
"lpep_dropoff_datetime", "store_and_fwd_flag",
"RatecodeID", "PULocationID",
"DOLocationID", "passenger_count",
"trip_distance", "fare_amount",
"extra", "mta_tax",
"tip_amount", "tolls_amount",
"ehail_fee", "improvement_surcharge", "total_amount",
"payment_type", "trip_type", "congestion_surcharge"
HAVING
COUNT(*) > 1;
-- 2. ์ดํ์ ํ์ธ
SELECT
SUM(CASE WHEN Trip_distance <= 1 THEN 1 END) AS "1. 1๋ง์ผ ์ดํ",
SUM(CASE WHEN Trip_distance > 1 AND Trip_distance <= 3 THEN 1 END) AS "2. 1๋ง์ผ ์ด๊ณผ 3๋ง์ผ ์ดํ",
SUM(CASE WHEN Trip_distance > 3 AND Trip_distance <= 7 THEN 1 END) AS "3. 3๋ง์ผ ์ด๊ณผ 7๋ง์ผ ์ดํ",
SUM(CASE WHEN Trip_distance > 7 AND Trip_distance <= 10 THEN 1 END) AS "4. 7๋ง์ผ ์ด๊ณผ 10๋ง์ผ ์ดํ",
SUM(CASE WHEN Trip_distance > 10 THEN 1 END) AS "5. 10๋ง์ผ ์ด๊ณผ"
FROM green_tripdata
WHERE lpep_pickup_datetime >= '2019-10-01' AND lpep_dropoff_datetime< '2019-11-01';
**-- "1. 1๋ง์ผ ์ดํ" "2. 1๋ง์ผ ์ด๊ณผ 3๋ง์ผ ์ดํ" "3. 3๋ง์ผ ์ด๊ณผ 7๋ง์ผ ์ดํ" "4. 7๋ง์ผ ์ด๊ณผ 10๋ง์ผ ์ดํ" "5. 10๋ง์ผ ์ด๊ณผ"
-- 104802 198924 109603 27678 35189**
- 1๋ง์ผ ์ดํ
- 1๋ง์ผ ์ด๊ณผ 3๋ง์ผ ์ดํ
- 3๋ง์ผ ์ด๊ณผ 7๋ง์ผ ์ดํ
- 7๋ง์ผ ์ด๊ณผ 10๋ง์ผ ์ดํ
- 10๋ง์ผ ์ด๊ณผ
๋ต:
- 104,802; 197,670; 110,612; 27,831; 35,281
104,802; 198,924; 109,603; 27,678; 35,189- 104,793; 201,407; 110,612; 27,831; 35,281
- 104,793; 202,661; 109,603; 27,678; 35,189
- 104,838; 199,013; 109,645; 27,688; 35,202
Question 4. ์ผ๋ณ ์ต์ฅ ์ดํ
์ดํ ๊ฑฐ๋ฆฌ๊ฐ ๊ฐ์ฅ ๊ธด ์น์ฐจ์ผ์ ์ธ์ ์๋์? ๊ณ์ฐ ์ ์น์ฐจ ์๊ฐ์ ๊ธฐ์ค์ผ๋ก ํ์ธ์.
SELECT DATE(lpep_pickup_datetime)
FROM green_tripdata
WHERE Trip_distance = (
SELECT MAX(Trip_distance) FROM green_tripdata
)
-- 2019-10-31ํ: ๊ฐ ๋ ์ง๋ณ๋ก ๊ฐ์ฅ ๊ธด ๊ฑฐ๋ฆฌ์ ํ ์ดํ๋ง ๊ณ ๋ คํ์ธ์.
- 2019-10-11
- 2019-10-24
- 2019-10-26
2019-10-31
Question 5. ์์ 3๊ฐ ์น์ฐจ ๊ตฌ์ญ
WITH trip AS (
SELECT "PULocationID",
SUM(total_amount) AS "total_amount"
FROM green_tripdata
WHERE DATE(lpep_pickup_datetime) = '2019-10-18'
GROUP BY "PULocationID"
ORDER BY "total_amount" DESC
)
SELECT zones."Zone" AS "Zone",
trip."PULocationID" AS "PULocationID",
trip."total_amount" AS "total_amount"
FROM zones
INNER JOIN trip ON trip."PULocationID" = zones."LocationID"
ORDER BY "total_amount" DESC
LIMIT 3;
-- "Zone" "PULocationID" "total_amount"
-- "East Harlem North" 74 18686.680000000084
-- "East Harlem South" 75 16797.260000000064
-- "Morningside Heights" 166 13029.7900000000322019-10-18์ผ์ total_amount๊ฐ 13,000์ ์ด๊ณผํ ์์ ์น์ฐจ ์์น๋ ์ด๋์ธ๊ฐ์?
๋ ์ง ํํฐ๋ง ์ lpep_pickup_datetime๋ง ๊ณ ๋ คํ์ธ์.
East Harlem North, East Harlem South, Morningside Heights- East Harlem North, Morningside Heights
- Morningside Heights, Astoria Park, East Harlem South
- Bedford, East Harlem North, Astoria Park
Question 6. ์ต๋ ํ
WITH trip AS (
SELECT "PULocationID",
"DOLocationID",
"tip_amount"
FROM green_tripdata
WHERE DATE(lpep_pickup_datetime) >= '2019-10-01' AND DATE(lpep_pickup_datetime) < '2019-11-01'
ORDER BY "tip_amount" DESC
)
SELECT PUZone."Zone" AS "PULocation",
DOZone."Zone" AS "DOLocation",
trip."tip_amount" AS "tip_amount"
FROM trip
INNER JOIN zones AS PUZone ON trip."PULocationID" = PUZone."LocationID"
INNER JOIN zones AS DOZone ON trip."DOLocationID" = DOZone."LocationID"
WHERE PUZone."Zone" = 'East Harlem North'
ORDER BY "tip_amount" DESC
LIMIT 1;
-- "JFK Airport"2019๋ 10์์ โEast Harlem Northโ ๊ตฌ์ญ์์ ์น์ฐจํ ์น๊ฐ๋ค ์ค์์ ์ด๋ ํ์ฐจ ๊ตฌ์ญ์์ ๊ฐ์ฅ ํฐ ํ์ด ์์๋์?
์ฃผ์: trip์ด ์๋ tip์
๋๋ค. ๊ตฌ์ญ์ ID๊ฐ ์๋ ์ด๋ฆ์ด ํ์ํฉ๋๋ค.
- Yorkville West
JFK Airport- East Harlem North
- East Harlem South
Question 7. Terraform ์ํฌํ๋ก์ฐ
๋ค์ ์ค ์ด๋ค ์์๊ฐ ๊ฐ๊ฐ ๋ค์ ์ํฌํ๋ก์ฐ๋ฅผ ์ค๋ช ํ๋์:
- ๊ณต๊ธ์ ํ๋ฌ๊ทธ์ธ ๋ค์ด๋ก๋ ๋ฐ ๋ฐฑ์๋ ์ค์
- ์ ์๋ ๋ณ๊ฒฝ์ฌํญ ์์ฑ ๋ฐ ๊ณํ ์๋ ์คํ
- terraform์ด ๊ด๋ฆฌํ๋ ๋ชจ๋ ๋ฆฌ์์ค ์ ๊ฑฐ
๋ต:
- terraform import, terraform apply -y, terraform destroy
- teraform init, terraform plan -auto-apply, terraform rm
- terraform init, terraform run -auto-approve, terraform destroy
- **
terraform init**, **terraform apply -auto-approve, terraform destroy** - terraform import, terraform apply -y, terraform rm