[프로그래머스 SQL] LV.1 조건에 맞는 회원수 구하기
❓ Question ❗ Answer SELECT COUNT(*) USERS FROM user_info WHERE joined LIKE '2021%' AND age BETWEEN 20 AND 29📌 Discussion 2021년에 가입한 사람을 추리기 위해 LIKE '2021%' 사용 비교연산자 BETWEEN a AND b 사용
❓ Question ❗ Answer SELECT COUNT(*) USERS FROM user_info WHERE joined LIKE '2021%' AND age BETWEEN 20 AND 29📌 Discussion 2021년에 가입한 사람을 추리기 위해 LIKE '2021%' 사용 비교연산자 BETWEEN a AND b 사용
❓ Question ❗ Answer SELECT animal_id FROM animal_ins WHERE name is null ORDER BY animal_id📌 Discussion is null로 결측치 확인
❓ Question ❗ Answer - LIMIT 사용 SELECT * FROM food_product ORDER BY PRICE DESC LIMIT 1 - sub-query 사용 SELECT * FROM food_product WHERE price = (SELECT MAX(price) FROM food_product)📌 Discussion WHERE 절에 sub query 사용하여 데이터 불러오기 가능
❓ Question ❗ Answer SELECT animal_id, name, DATE_FORMAT(datetime,'%Y-%m-%d') FROM animal_ins ORDER BY animal_id📌 Discussion date_fomat을 활용하여 datetime 형식 데이터를 변경
❓ Question ❗ Answer SELECT max(price) MAX_PRICE FROM product SELECT price MAX_PRICE FROM product ORDER BY price DESC LIMIT 1 📌 Discussion SELECT 절에 max 함수 사용하여 호출 가격 순 내림차순 정렬 후 맨 위 한개만 호출
❓ Question ❗ Answer SELECT warehouse_id, warehouse_name, address, IFNULL(freezer_yn, 'N') FROM food_warehouse WHERE address LIKE '경기%' ORDER BY warehouse_id; 📌 Discussion LIKE '경기%'로 '경기'으로 시작하는 데이터를 가져온다. IFNULL(freezer_yn, 'N')으로 냉동창고가 없는 곳은 'N'으로 출력한다.
❓ Question ❗ Answer SELECT factory_id, factory_name, address FROM food_factory WHERE address like '강원%' ORDER BY factory_id📌 Discussion LIKE '강원%'로 '강원'으로 시작하는 데이터를 가져
❓ Question ❗ Answer SELECT animal_type, IFNULL(name,'No name') name, sex_upon_intake FROM animal_ins ORDER BY animal_id 📌 Discussion IFNULL로 null값은 'No name'으로 대체해 줌