시간 | 내용 |
---|---|
09:00-10:00 | 코드카타 |
10:00-10:30 | 오전 스크럼 |
10:30-12:00 | 팀 과제 데이터 분석 |
12:00-13:00 | 점심식사 |
13:00-14:00 | ADsP 강의 수강 |
14:00-15:00 | SQL 라이브 세션 |
15:00-18:00 | 팀 과제 데이터 분석 |
18:00-19:00 | 저녁식사 |
19:00-20:00 | 데이터 분석 결과 공유 |
20:00-20:30 | 저녁 스크럼 |
20:30-21:00 | TIL 작성 |
21:00-23:00 | 부족한 부분 보충 |
SELECT
FLOOR(price/10000)*10000 AS price_group
, COUNT(*) AS products
FROM
product
GROUP BY
price_group
ORDER BY
price_group
;
처음에는 아래와 같이 생각했다:
SELECT
CASE
WHEN price < 10000 THEN 0
WHEN price < 20000 THEN 10000
WHEN price < 30000 THEN 20000
WHEN price < 40000 THEN 30000
WHEN price < 50000 THEN 40000
WHEN price < 60000 THEN 50000
WHEN price < 70000 THEN 60000
WHEN price < 80000 THEN 70000
WHEN price < 90000 THEN 80000
WHEN price < 10000 THEN 90000
END AS price_group
, COUNT(*) AS products
FROM
product
GROUP BY
price_group
ORDER BY
price_group
;
추가: DIV 함수(나누었을 때 몫을 구하는 함수) 이용
SELECT
10000*(price DIV 10000) AS price_group
, COUNT(*) AS products
FROM
product
GROUP BY
price_group
ORDER BY
price_group
;
-- WITH 서브 쿼리 활용
WITH p AS (
SELECT
*
, TRUNCATE(price, -4) AS pg
FROM
product
)
SELECT
pg AS price_group
, COUNT(*) AS products
FROM
p
GROUP BY
pg
ORDER BY
price_group
;
-- 인라인 뷰 서브쿼리 활용
SELECT
pg.price_group
, COUNT(*) AS products
FROM (
SELECT
*
, TRUNCATE(price, -4) AS price_group
FROM
product
) pg
GROUP BY
pg.price_group
ORDER BY
pg.price_group
;
def solution(age):
year = 2022
answer = year - age + 1
return answer
solution = lambda age : 2022 - int(age) + 1
def solution(age):
answer = 2022-int(age)+1
return answer
이커머스 데이터 분석
시간별 비교
→ Pivot Table
WITH RECURSIVE temp as (
(SELECT 0 HOUR)
union
(SELECT HOUR+1 FROM temp where HOUR < 23)
)
SELECT temp.HOUR, IFNULL(A.COUNT, 0) COUNT
FROM temp LEFT OUTER JOIN (
SELECT HOUR(DATETIME) HOUR, COUNT(*) COUNT
FROM ANIMAL_OUTS
GROUP BY HOUR
ORDER BY HOUR) A
ON temp.HOUR = A.HOUR;