[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/MYSQL] 36. ๋ณดํ˜ธ์†Œ์—์„œ ์ค‘์„ฑํ™”ํ•œ ๋™๋ฌผ

2025. 4. 3. 14:06ยท๋‚ด์ผ๋ฐฐ์›€์บ ํ”„/SQL ์ฝ”๋“œ์นดํƒ€

โ‡๏ธ ๋ฌธ์ œ ์„ค๋ช…

๋ณดํ˜ธ์†Œ์— ๋“ค์–ด์˜ฌ ๋‹น์‹œ์—๋Š” ์ค‘์„ฑํ™”๋˜์ง€ ์•Š์•˜์ง€๋งŒ, ๋ณดํ˜ธ์†Œ๋ฅผ ๋‚˜๊ฐˆ ๋‹น์‹œ์—๋Š” ์ค‘์„ฑํ™”๋œ ๋™๋ฌผ์˜ ์•„์ด๋””์™€ ์ƒ๋ฌผ ์ข…, ์ด๋ฆ„์„ ์กฐํšŒํ•˜๋Š” ์•„์ด๋”” ์ˆœ์œผ๋กœ ์กฐํšŒํ•˜๋Š” SQL ๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

https://school.programmers.co.kr/learn/courses/30/lessons/59045

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

SW๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ํ‰๊ฐ€, ๊ต์œก, ์ฑ„์šฉ๊นŒ์ง€ Total Solution์„ ์ œ๊ณตํ•˜๋Š” ๊ฐœ๋ฐœ์ž ์„ฑ์žฅ์„ ์œ„ํ•œ ๋ฒ ์ด์Šค์บ ํ”„

programmers.co.kr

 

โ‡๏ธ ๋ฌธ์ œ ํ•ด์„

1. ๋ณดํ˜ธ์†Œ ๋“ค์–ด์˜ค๊ธฐ ์ „์— ์ค‘์„ฑํ™”๋˜์ง€ ์•Š์€ ์ƒํƒœ(ANIMAL_INS ๊ธฐ์ค€)
2. ๋ณดํ˜ธ์†Œ๋ฅผ ๋‚˜๊ฐˆ ๋•Œ๋Š” ์ค‘์„ฑํ™”๊ฐ€ ๋œ ์ƒํƒœ(ANIMAL_OUTS ๊ธฐ์ค€)
3. ์•„์ด๋””์ˆœ์œผ๋กœ ์กฐํšŒ

 

โ‡๏ธ ์ž‘์„ฑ ์ฝ”๋“œ

SELECT I.ANIMAL_ID, I.ANIMAL_TYPE, I.NAME
FROM ANIMAL_INS I JOIN ANIMAL_OUTS O ON I.ANIMAL_ID = O.ANIMAL_ID
WHERE I.SEX_UPON_INTAKE LIKE "%Intact%" 
      AND (O.SEX_UPON_OUTCOME LIKE "%Spayed%" OR O.SEX_UPON_OUTCOME LIKE "%Neutered%")
ORDER BY 1

 

โ‡๏ธ ์ฝ”๋“œ ํ’€์ด

1. ๋ณดํ˜ธ์†Œ ๋“ค์–ด์˜ค๊ธฐ ์ „์— ์ค‘์„ฑํ™”๋˜์ง€ ์•Š์€ ์ƒํƒœ(ANIMAL_INS ๊ธฐ์ค€)

2. ๋ณดํ˜ธ์†Œ๋ฅผ ๋‚˜๊ฐˆ ๋•Œ๋Š” ์ค‘์„ฑํ™”๊ฐ€ ๋œ ์ƒํƒœ(ANIMAL_OUTS ๊ธฐ์ค€)

WHERE I.SEX_UPON_INTAKE LIKE "%Intact%" 
      AND (O.SEX_UPON_OUTCOME LIKE "%Spayed%" OR O.SEX_UPON_OUTCOME LIKE "%Neutered%")

 

3. ์•„์ด๋””์ˆœ์œผ๋กœ ์กฐํšŒ

ORDER BY 1

 

โ‡๏ธ ์‹คํ–‰ ๊ฒฐ๊ณผ

 

'๋‚ด์ผ๋ฐฐ์›€์บ ํ”„ > SQL ์ฝ”๋“œ์นดํƒ€' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/MYSQL] 38. ์กฐ๊ฑด๋ณ„๋กœ ๋ถ„๋ฅ˜ํ•˜์—ฌ ์ฃผ๋ฌธ์ƒํƒœ ์ถœ๋ ฅํ•˜๊ธฐ  (0) 2025.04.05
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/MYSQL] 37. ์กฐ๊ฑด์— ๋งž๋Š” ๋„์„œ์™€ ์ €์ž ๋ฆฌ์ŠคํŠธ ์ถœ๋ ฅํ•˜๊ธฐ  (0) 2025.04.04
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/MYSQL] 35. ์˜ค๋žœ ๊ธฐ๊ฐ„ ๋ณดํ˜ธํ•œ ๋™๋ฌผ(2)  (1) 2025.04.02
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/MYSQL] 34. ์žˆ์—ˆ๋Š”๋ฐ์š” ์—†์—ˆ์Šต๋‹ˆ๋‹ค.  (0) 2025.04.01
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/MYSQL] 33. ์ƒํ’ˆ ๋ณ„ ์˜คํ”„๋ผ์ธ ๋งค์ถœ ๊ตฌํ•˜๊ธฐ  (0) 2025.03.31
'๋‚ด์ผ๋ฐฐ์›€์บ ํ”„/SQL ์ฝ”๋“œ์นดํƒ€' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
  • [ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/MYSQL] 38. ์กฐ๊ฑด๋ณ„๋กœ ๋ถ„๋ฅ˜ํ•˜์—ฌ ์ฃผ๋ฌธ์ƒํƒœ ์ถœ๋ ฅํ•˜๊ธฐ
  • [ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/MYSQL] 37. ์กฐ๊ฑด์— ๋งž๋Š” ๋„์„œ์™€ ์ €์ž ๋ฆฌ์ŠคํŠธ ์ถœ๋ ฅํ•˜๊ธฐ
  • [ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/MYSQL] 35. ์˜ค๋žœ ๊ธฐ๊ฐ„ ๋ณดํ˜ธํ•œ ๋™๋ฌผ(2)
  • [ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/MYSQL] 34. ์žˆ์—ˆ๋Š”๋ฐ์š” ์—†์—ˆ์Šต๋‹ˆ๋‹ค.
aggeeeee
aggeeeee
ใ€€ φ(๏ผŽ๏ผŽ;)ใ€€๐Ÿ”œใ€€\_ใธ(โ–ญ-โ–ญ)โœจ
  • aggeeeee
    ๐Ÿฅ” ๋‹˜์˜ ๋ธ”๋กœ๊ทธ
    aggeeeee
    • ๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ (155)
      • Today I Learned (25)
      • ๋‚ด์ผ๋ฐฐ์›€์บ ํ”„ (115)
        • ๋ณธ์บ ํ”„ ๊ณผ์ œ (17)
        • ์‚ฌ์ „์บ ํ”„ ๊ณผ์ œ (23)
        • SQL ์ฝ”๋“œ์นดํƒ€ (44)
        • ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ฝ”๋“œ์นดํƒ€ (31)
      • ๐Ÿ’ป๐Ÿš€ (15)
        • Java (7)
        • Git & GitHub (1)
        • CS (4)
        • Spring & SpringBoot (3)
  • ๋งํฌ

  • ์ตœ๊ทผ ๊ธ€

  • ์ „์ฒด
    ์˜ค๋Š˜
    ์–ด์ œ
  • hELLOยท Designed By์ •์ƒ์šฐ.v4.10.3
aggeeeee
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/MYSQL] 36. ๋ณดํ˜ธ์†Œ์—์„œ ์ค‘์„ฑํ™”ํ•œ ๋™๋ฌผ
์ƒ๋‹จ์œผ๋กœ

ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”