서브쿼리
-
12/5스파르타/TIL(Today I Learned) 2023. 12. 5. 16:30
오늘도 어김없이 프로그래머스 문제를 풀다가 막혀 !도움을 하던중 정말 깔끔하게 짠 코드를 보고 이해하며 감탄한 코드가 있어 가져와봤다. 문제 : 데이터 분석 팀에서는 우유(Milk)와 요거트(Yogurt)를 동시에 구입한 장바구니가 있는지 알아보려 합니다. 우유와 요거트를 동시에 구입한 장바구니의 아이디를 조회하는 SQL 문을 작성해주세요. 이때 결과는 장바구니의 아이디 순으로 나와야 합니다. cart_products의 테이블이다. 보면 name에 두가지 조건 1. name = 'Milk' 2. name = 'Yogurt' 를 동시에 만족해야 한다 하지만 그냥 코드를 한번에 작성해서 하려면 두 조건을 동시에 만족하기는 어렵다. 그래서 서브쿼리로 조건 한개를 처리한 후 나머지 조건을 처리하는 방법을 소개하..