EEALL@ONCE

๐Ÿ“Š ์ฟผ๋ฆฌ ์Šคํ„ฐ๋”” - 1. ๊ฐ€์ž…์ž๊ฐ€ ๋‹น์ผ ํ™œ๋™์„ ํ•˜๋Š”๊ฐ€? ๋ณธ๋ฌธ

Data๐Ÿ“Š/SQL ์ฟผ๋ฆฌ ์Šคํ„ฐ๋””

๐Ÿ“Š ์ฟผ๋ฆฌ ์Šคํ„ฐ๋”” - 1. ๊ฐ€์ž…์ž๊ฐ€ ๋‹น์ผ ํ™œ๋™์„ ํ•˜๋Š”๊ฐ€?

์˜ฌ์—ฃ์›์Šค 2023. 7. 28. 17:32
728x90

์ฃผ๊ฐ„ ํ™œ์„ฑ ์œ ์ €๊ฐ€ ๋–จ์–ด์ง€๊ณ  ์žˆ๋‹ค... ์™œ๊ทธ๋Ÿฐ๊ฐ€?! ์ด์œ ๋ฅผ ์ฐพ์•„๋ณด์ž . 

 

Table 1: Users : ๊ณ ๊ฐ ํ…Œ์ด๋ธ” 

Table 2: Events : ๊ณ ๊ฐ์ด ํ•œ ํ–‰์œ„ ๊ธฐ๋ก ํ…Œ์ด๋ธ” ( ์˜ˆ๋ฅผ ๋“ค์–ด ์ข‹์•„์š” ๋ˆ„๋ฅด๊ธฐ ๋“ฑ)

Table 3: Email Events : ๊ณ ๊ฐ์ด ์ด๋ฉ”์ผ์—์„œ ํ•œ ํ–‰๋™ ๊ธฐ๋ก ํ•œ ํ…Œ์ด๋ธ” 

๐Ÿ’ก Solving the case

1. One of the easiest things to check is growth, both because it's easy to measure and because most companies (Yammer included) track this closely already. In this case, you have to make it yourself, though. You'll notice that nothing has really changed about the growth rate—it continues to be high during the week, low on weekends:

1. ๊ฐ€์žฅ ์‰ฝ๊ฒŒ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ ์ค‘ ํ•˜๋‚˜๋Š” ์„ฑ์žฅ๋ฅ ์ธ๋ฐ, ์ด๋Š” ์ธก์ •์ด ์‰ฝ๊ธฐ ๋•Œ๋ฌธ์ด๊ธฐ๋„ ํ•˜๊ณ , ๋Œ€๋ถ€๋ถ„์˜ ๊ธฐ์—…(Yammer ํฌํ•จ)์ด ์ด๋ฏธ ์ด๋ฅผ ๋ฉด๋ฐ€ํžˆ ์ถ”์ ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ด ๊ฒฝ์šฐ ์„ฑ์žฅ๋ฅ ์— ๋Œ€ํ•ด ์ง์ ‘ ๊ฒฐ์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ฃผ์ค‘์—๋Š” ๋†’์€ ์„ฑ์žฅ๋ฅ ์„ ์œ ์ง€ํ•˜๊ณ  ์ฃผ๋ง์—๋Š” ๋‚ฎ์€ ์„ฑ์žฅ๋ฅ ์„ ์œ ์ง€ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค:

๋ผ๊ณ  ์˜ˆ์‹œ ๋‹ต์„ ์ฃผ๊ณ  ์žˆ๋Š”๋ฐ... 

ํ•ด๋‹น ์ฟผ๋ฆฌ๋ฅผ ์ด๋Ÿฐ ์‹์œผ๋กœ ์งฐ๋˜๋ฐ... 

SELECT DATE(created_at) AS day,
       COUNT(*) AS all_users,
       SUM(CASE WHEN activated_at IS NOT NULL THEN 1 ELSE 0 END) AS activated_users
FROM tutorial.yammer_users
WHERE created_at >= '2014-06-01'
  AND created_at < '2014-09-01'
GROUP BY DATE(created_at)
ORDER BY DATE(created_at);

 

created_at์„ ๊ธฐ์ค€์œผ๋กœ day๋กœ ๋‚˜๋ˆ ์„œ ๊ณ„์‚ฐํ•œ๋‹ค.  

ํ•ด๋‹น ๋‚  ๊ฐ€์ž…ํ•œ ์ˆ˜์™€ ๊ทธ ์‚ฌ๋žŒ์ด ๊ทธ ๋‚  ํ™œ๋™ํ–ˆ๋ƒ๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. 

๊ทผ๋ฐ, ์‚ฌ์‹ค ๊ทธ๋ ‡๊ฒŒ ๊นŒ์ง€ ์˜๋ฏธ์žˆ๋Š” ๋ถ„์„์ธ์ง€ ๋ชจ๋ฅด๊ฒ ๋‹ค. ๊ฐ€์ž…ํ•œ ์‚ฌ๋žŒ์€ ๋ณดํ†ต ๊ทธ ๋‚ ์€ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋‚˜ ์‹ถ๋‹ค.. 

์–ด๋–ค ํŠธ๋žœ๋“œ๋ฅผ ์ฝ์–ด๋‚ผ ์ˆ˜ ์žˆ๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ๋‹ค. 

ํ™œ๋™ ์œ ์ €์˜ ๊ฐ์†Œ๋ฅผ ๋ณด๊ณ  ์‹ถ์œผ๋ฉด, ๊ทธ๋‚  ๊ฐ€์ž…ํ•œ ์‚ฌ๋žŒ์˜ ๋‹น์ผ ํ™œ๋™ ์œ ๋ฌด๊ฐ€ ๋ญ๊ฐ€ ์ค‘์š”ํ• ๊นŒ.. 

๋‚ด๊ฐ€ ๋†“์น˜๋Š” insight๊ฐ€ ์žˆ๋Š”๊ฑธ๊นŒ.. ๋ฌดํŠผ ์ € ์ฟผ๋ฆฌ๋ฌธ์€ ๋‹น์ผ ๊ฐ€์ž…์ž์˜ ๋‹น์ผ ํ™œ๋™ ์œ ๋ฌด๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.. 

 

๐ŸŸ  case 

CASE ํ‘œํ˜„์‹: CASE ํ‘œํ˜„์‹์€ ํŠน์ • ์กฐ๊ฑด์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๊ฑฐ๋‚˜ ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ

๋˜ํ•œ CASE ํ‘œํ˜„์‹์„ ์‚ฌ์šฉํ•˜์—ฌ ์ƒˆ๋กœ์šด ์ปฌ๋Ÿผ์„ ์ƒ์„ฑํ•  ์ˆ˜๋„ ์žˆ์Œ 

 

SELECT name, score,
       CASE
         WHEN score >= 90 THEN 'A'
         WHEN score >= 80 THEN 'B'
         WHEN score >= 70 THEN 'C'
         ELSE 'F'
       END AS grade
FROM students;

students ํ…Œ์ด๋ธ”์˜ score ์ปฌ๋Ÿผ์— ๋”ฐ๋ผ ๊ฐ ํ•™์ƒ์˜ ์„ฑ์  ๋“ฑ๊ธ‰์„ ๊ณ„์‚ฐํ•˜์—ฌ grade๋ผ๋Š” ์ƒˆ๋กœ์šด ์ปฌ๋Ÿผ์œผ๋กœ ํ‘œํ˜„ํ•ด์คŒ 

728x90