Banner

My Tech Blog (์ฝ”๋”ฉํ…Œ์ŠคํŠธ)

๐Ÿ“‘ 1. ๋ฌธ์ œ์„ค๋ช…โŒ 2. ์‹คํŒจํ•œ ์‹œ๋„์ฝ”๋“œ๋Š” ์ž‘๋™ํ•˜์ง€๋งŒ ์ •๋‹ต ์ฒ˜๋ฆฌ X์ด์œ : CAR_ID ์ค‘๋ณต๋จSELECT A.Car_idFROM Car_rental_company_car A JOIN Car_rental_company_rental_history B ON A.Car_id = B.Car_idWHERE A.Car_type = '์„ธ๋‹จ' AND B.Start_date BETWEEN '2022-10-01' AND '2022-10-31'ORDER BY A.Car_id DESC;โญ 3. ์ •๋‹ต์ฝ”๋“œCAR_ID ์ค‘๋ณต์ด ์—†์–ด์•ผ ํ•˜๋ฉฐ -> DISTINCT๋Œ€์—ฌ ๊ธฐ๋ก์ด ์žˆ๋Š” -> ON A.CAR_ID = B.CAR_IDSELECT DISTINCT(A.Car_id)FROM ..
๐Ÿ“‘ 1. ๋ฌธ์ œ์„ค๋ช…โญ 2. ์ •๋‹ต์ฝ”๋“œ์ถœ๊ณ ์ผ์ด 2022-05-01 ๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด '์ถœ๊ณ ์™„๋ฃŒ'๋Šฆ์œผ๋ฉด ์ถœ๊ณ  ๋Œ€๊ธฐ, ์—†์œผ๋ฉด ์ถœ๊ณ  ๋ฏธ์ •์ด๊ณ  ํ•ด๋‹น ์ปฌ๋Ÿผ๋ช…์€ ์ถœ๊ณ ์—ฌ๋ถ€๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ์„ค์ •์–ด๋ ค์šด ๋ถ€๋ถ„์€ ์—†๋Š” ์‰ฌ์šด ๋ฌธ์ œ๐ŸฅณSELECT Order_id, Product_id, DATE_FORMAT(Out_date,'%Y-%m-%d') AS Out_date, CASE WHEN Out_date '2022-05-01' THEN '์ถœ๊ณ ๋Œ€๊ธฐ' ELSE '์ถœ๊ณ ๋ฏธ์ •'END AS ์ถœ๊ณ ์—ฌ๋ถ€FROM Food_orderORDER BY Order_id;
๐Ÿ“‘ 1. ๋ฌธ์ œ์„ค๋ช…โญ 2. ์ •๋‹ต์ฝ”๋“œSELECT Animal_id, name, CASE WHEN Sex_upon_intake LIKE '%Neutered%' OR Sex_upon_intake LIKE '%Spayed%' THEN 'O' ELSE 'X' END AS ์ค‘์„ฑํ™”FROM ANIMAL_INSORDER BY ANIMAL_ID; ๐Ÿ˜Š 3. TMIANSI SQL ํ‘œ์ค€์—์„œ๋Š” ALIAS ์— ์ž‘์€๋”ฐ์˜ดํ‘œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ํ—ˆ์šฉ๋˜์ง€ ์•Š์ง€๋งŒ ์จ๋„ ์ƒ๊ด€์€ ์—†๋‹ค. (๋‚˜๋Š” ๋”ฐ์˜ดํ‘œ ์ผ์Œ)SELECT Animal_id, name, CASE WHEN Sex_upon_intake LIKE '%Neutered%' ..
๐Ÿ“‘ 1. ๋ฌธ์ œ์„ค๋ช…๐Ÿ’ก 2. ์ ‘๊ทผ๋ฐฉ์‹ ๋ฌธ์ œ ์ œํ•œ์กฐ๊ฑด1. ํ•œ ๋ฒˆ์— ์ตœ๋Œ€ ๋‘๋ช…๊นŒ์ง€ ๋ณดํŠธ์— ํƒœ์šธ ์ˆ˜ ์žˆ์Œ2. ๋ชธ๋ฌด๊ฒŒ ํ•ฉ์ด `limit` ์ดํ•˜์—ฌ์•ผ ํ•จ ๋”ฐ๋ผ์„œ ์ตœ์†Œ๋ณดํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ „๋žต์„ ์งœ๋ ค๋ฉด ๋ฐฐ์—ด์„ ์ •๋ ฌํ•˜์—ฌ ๊ฐ€์žฅ ๊ฐ€๋ฒผ์šด ์‚ฌ๋žŒ + ๊ฐ€์žฅ ๋ฌด๊ฑฐ์šด ์‚ฌ๋žŒ ์กฐํ•ฉ์„ ์ง์ง€์–ด์•ผ ํ•จ.๊ฐ€์žฅ ํฐ ๋ชธ๋ฌด๊ฒŒ๋ฅผ ๊ฐ€์ง„ ์‚ฌ๋žŒ์„ ์ตœ๋Œ€ํ•œ ๋นจ๋ฆฌ ์ฒ˜๋ฆฌํ•˜๋ฉด์„œ๋„ ๋ณดํŠธ ์‚ฌ์šฉ์„ ์ค„์ผ ๊ฐ€๋Šฅ์„ฑ์ด ๋†’๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.๋งŒ์•ฝ ๋‘ ์‚ฌ๋žŒ์˜ ๋ชธ๋ฌด๊ฒŒ ํ•ฉ์ด limit ์ดํ•˜๋ผ๋ฉด, ํ•œ ๋ณดํŠธ์— ํƒœ์šธ ์ˆ˜ ์žˆ๋‹ค. ํ•ฉ์ด limit์„ ์ดˆ๊ณผํ•œ๋‹ค๋ฉด, ๋ฌด๊ฑฐ์šด ์‚ฌ๋žŒ์„ ๋ฐ˜๋“œ์‹œ ํ•œ ๋ช…๋งŒ ๋ณดํŠธ์— ํƒœ์›Œ์•ผ ํ•œ๋‹ค.์ด๋ ‡๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ด ๋‚จ์€ ์‚ฌ๋žŒ๋“ค์„ ํšจ์œจ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ตœ์„ ์˜ ์„ ํƒ์ด๋‹ค. โญ 3. ์ •๋‹ต์ฝ”๋“œimport java.util.*;class Solution {    public int solution(i..
๐Ÿ“‘ 1. ๋ฌธ์ œ์„ค๋ช…๐Ÿ’ก 2. ์ ‘๊ทผ๋ฐฉ์‹์ด ๋ฌธ์ œ ํ•ต์‹ฌ์€ ์กฐ๊ฑด์— ๋”ฐ๋ผ์„œ STATUS ๋ผ๋Š” ์ปฌ๋Ÿผ์— ๋‹ค๋ฅธ ๊ฒฐ๊ณผ๊ฐ’์„ ๋ณด์—ฌ์ฃผ๋Š” ๊ฒƒ์ด๋‹ค์ž๋ฐ”์—์„œ ์กฐ๊ฑด๋ฌธ์œผ๋กœ IF๋‚˜ CASE๋ฌธ ์“ฐ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ MySQL ์—์„œ๋Š” SELECT ์ ˆ์— CASE ๋ฌธ์„ ์จ ์ค„ ์ˆ˜ ์žˆ๋‹ค.CASE WHEN ์ปฌ๋Ÿผ๋ช… = '์กฐ๊ฑด' THEN '๊ฒฐ๊ณผ๊ฐ’' ํ•ด ์ฃผ๋ฉด ์กฐ๊ฑด์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ๊ฒฐ๊ณผ๊ฐ€ ๋„์ถœ๋œ๋‹ค.๊ทธ๋ฆฌ๊ณ  CASE ๋ฌธ์„ ๋๋‚ผ ๋•Œ๋Š” END AS ๋ณ„์นญ์„ ์‚ฌ์šฉํ•œ๋‹ค ๋งŒ์•ฝ์— ๋‚˜์—ดํ•œ ์กฐ๊ฑด์— ํ•ด๋‹นํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์˜ ๊ธฐ๋ณธ ๊ฐ’์„ ์ฃผ๊ณ  ์‹ถ๋‹ค๋ฉด WHEN ๋Œ€์‹  ELSE ์ ˆ์— ๊ธฐ๋ณธ๊ฐ’์„ ์„ธํŒ…ํ•ด ์ฃผ๋ฉด ๋œ๋‹ค. โญ 3. ์ •๋‹ต์ฝ”๋“œ๊ณ„์† ํ‹€๋ ค์„œ ์ถœ๋ ฅ์€ ์ž˜ ๋˜๋Š”๋ฐ ์™œ ํ‹€๋ฆฌ๋‚˜ ํ–ˆ๋”๋‹ˆ MySQL ์—์„œ ๊ธฐ๋ณธ๊ฐ’์€ ์˜ค๋ฆ„์ฐจ์ˆœ์ด์—ˆ๋‹ค์ฒ˜์Œ์— ๋‚ด๋ฆผ์ฐจ์ˆœ์ด ๊ธฐ๋ณธ๊ฐ’์ด๋ผ ์ƒ๊ฐํ•˜๊ณ  ์ƒ๋žตํ–ˆ์ŒORDER BY BOARD_ID;๋งŒ ์ผ๋”๋‹ˆ ๊ณ„..
๐Ÿ“‘ 1. ๋ฌธ์ œ์„ค๋ช…๐Ÿ’ก 2. ์ ‘๊ทผ๋ฐฉ์‹WHERE์ ˆ์ด๋ž‘ HAVING ์ ˆ ์“ฐ์ž„์ด ๋„ˆ๋ฌด๋„ˆ๋ฌด ํ—ท๊ฐˆ๋ฆฐ๋‹ค.  ์™œ HAVING์„ ์‚ฌ์šฉํ•˜๋Š”๊ฐ€? ์ด ๋ฌธ์ œ์—์„œ๋Š” ํ‰๊ท  ๋Œ€์—ฌ ๊ธฐ๊ฐ„(AVG)์„ ๊ณ„์‚ฐํ•œ ํ›„ ํ•ด๋‹น ๊ฐ’์ด 7 ์ด์ƒ์ธ ๊ทธ๋ฃน๋งŒ ํ•„ํ„ฐ๋งํ•ด์•ผ ํ•œ๋‹ค.ํ‰๊ท ์„ ๊ณ„์‚ฐํ•˜๋ ค๋ฉด ๋จผ์ € CAR_ID ๋ณ„๋กœ ๊ทธ๋ฃนํ™”๋ฅผ ํ•ด์•ผํ•œ๋‹ค.์ดํ›„์— ์กฐ๊ฑด์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ ˆ์ด ๋ฐ”๋กœ HAVING์ด๋‹ค.์ฆ‰, WHERE ์ ˆ๋กœ๋Š” ๊ทธ๋ฃนํ™” ์ดํ›„์˜ ์ง‘๊ณ„ ๊ฒฐ๊ณผ๋ฅผ ํ•„ํ„ฐ๋งํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ˜๋“œ์‹œ HAVING์„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค. ์–ธ์ œ WHERE์ ˆ์„ ์จ์•ผ ํ•˜๊ณ , ์–ธ์ œ HAVING ์ ˆ์„ ์จ์•ผ ํ•˜๋Š”์ง€ ์ •๋ง ํ—ท๊ฐˆ๋ฆฐ๋‹ค.์ด๊ฑด SQL ์ฟผ๋ฆฌ๋ฌธ ์‹คํ–‰ ์ˆœ์„œ์™€ ๊ด€๋ จ์ด ์žˆ๋‹ค.FROM - WHERE - GROUP BY - HAVING - SELECT - ORDER BYHAVING์€ GROUP BY ์ดํ›„ ์‹คํ–‰..
๐Ÿ“‘ 1. ๋ฌธ์ œ์„ค๋ช…๐Ÿ’ก 2. ์ ‘๊ทผ๋ฐฉ์‹์™„์ „ํƒ์ƒ‰์€ ์•ˆ๋˜๋Š” ์ด์œ ๋ฌธ์ œ์—์„œ number≤1,000,000์œผ๋กœ ์ตœ๋Œ€ ๋ฐฑ๋งŒ์ž๋ฆฌ ์ˆซ์ž๊ฐ€ ๋  ์ˆ˜ ์žˆ๋‹ค. number ๊ฐ’์ด ๋„ˆ๋ฌด ์ปค์„œ ์™„์ „ ํƒ์ƒ‰์€ ํ˜„์‹ค์ ์œผ๋กœ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค. k๋Š” 1 ์ด์ƒ len(number) - 1 ์ดํ•˜์˜ˆ๋ฅผ ๋“ค์–ด, ์ˆซ์ž๊ฐ€ 1,000,000์ž๋ฆฌ๋ผ๋ฉด ์ตœ๋Œ€ 999,999๊ฐœ์˜ ์ˆซ์ž๋ฅผ ์ œ๊ฑฐํ•ด์•ผ ํ•œ๋‹ค. ์™œ ๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์จ์•ผ ํ•˜๋Š”๊ฐ€?์ˆซ์ž๋ฅผ ํ•œ ๋ฒˆ๋งŒ ์ˆœํšŒํ•˜๋ฉด์„œ ์ ์ ˆํ•œ ์ˆซ์ž๋ฅผ ์„ ํƒํ•˜๊ฑฐ๋‚˜ ์ œ๊ฑฐํ•œ๋‹ค. ์ˆซ์ž๊ฐ€ ๋ฐฑ๋งŒ ์ž๋ฆฌ์—ฌ๋„ 1,000,000๋ฒˆ์˜ ๋น„๊ต๋งŒ ํ•˜๋ฉด ๋˜๊ธฐ ๋•Œ๋ฌธ์— ํšจ์œจ์ด ์ข‹๋‹ค.๋ฌธ์ œ์˜ ํ•ต์‹ฌ = '์•ž์—์„œ๋ถ€ํ„ฐ ๋’ค๋กœ ํฐ ์ˆซ์ž ์œ ์ง€'์•ž์ž๋ฆฌ๋ถ€ํ„ฐ ์ˆœ์„œ๋Œ€๋กœ ์ˆซ์ž๋ฅผ ์„ ํƒํ•˜๋ฉฐ ํฐ ์ˆซ์ž๋ฅผ ์œ ์ง€ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ’€์–ด์•ผ ํ•œ๋‹ค.๋‚˜๋Š” ์ด์ค‘ํฌ๋ฌธ์œผ๋กœ ํ’€์—ˆ๋Š”๋ฐ ๋‹ค๋ฅธ ๋ถ„๋“ค์ด ํ’€์ดํ•œ ๊ฑธ ๋ณด๋‹ˆ ์Šคํƒ์„ ์‚ฌ์šฉํ•ด ๋”..
๐Ÿ“‘ 1. ๋Œ€์†Œ๋ฌธ์ž ๋ฐ”๊ฟ”์„œ ์ถœ๋ ฅํ•˜๊ธฐimport java.util.Scanner;public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String a = sc.next(); System.out.println(swapCase(a)); } public static String swapCase(String str) { StringBuilder result = new StringBuilder(); for(char c:str.toCharArray()) { if(Character.isUpperCase(c) ) { resu..
์ธ์ ˆ๋ฏธ์˜€๋˜๊ฒƒ
'์ฝ”๋”ฉํ…Œ์ŠคํŠธ' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก
์ƒ๋‹จ์œผ๋กœ