프로그래머스
-
프로그래머스 - 저자 별 카테고리 별 매출액 집계하기카테고리 없음 2024. 1. 8. 12:17
저자 별 카테고리 별 매출액 집계하기 2022년 1월의 도서 판매 데이터를 기준으로 저자 별, 카테고리 별 매출액(TOTAL_SALES = 판매량 * 판매가) 을 구하여, 저자 ID(AUTHOR_ID), 저자명(AUTHOR_NAME), 카테고리(CATEGORY), 매출액(SALES) 리스트를 출력하는 SQL문을 작성해주세요.결과는 저자 ID를 오름차순으로, 저자 ID가 같다면 카테고리를 내림차순 정렬해주세요. with sales as ( SELECT BOOK.PRICE, BOOK.AUTHOR_ID, BOOK.CATEGORY, SALES.SALES FROM BOOK_SALES as SALES JOIN BOOK ON BOOK.BOOK_ID = SALES.BOOK_ID WHERE date_format(SALE..
-
프로그래머스 - 서울에 위치한 식당 목록 출력하기SQL 문제 2024. 1. 5. 15:34
서울에 위치한 식당 목록 출력하기 REST_INFO와 REST_REVIEW 테이블에서 서울에 위치한 식당들의 식당 ID, 식당 이름, 음식 종류, 즐겨찾기수, 주소, 리뷰 평균 점수를 조회하는 SQL문을 작성해주세요. 이때 리뷰 평균점수는 소수점 세 번째 자리에서 반올림 해주시고 결과는 평균점수를 기준으로 내림차순 정렬해주시고, 평균점수가 같다면 즐겨찾기수를 기준으로 내림차순 정렬해주세요 -- 코드를 입력하세요 SELECT INFO.REST_ID, INFO.REST_NAME, INFO.FOOD_TYPE, INFO.FAVORITES, INFO.ADDRESS, ROUND(AVG(REVIEW.REVIEW_SCORE),2) AS SCORE FROM REST_INFO as INFO left join REST_RE..
-
12/07스파르타/TIL(Today I Learned) 2023. 12. 7. 02:48
문제 CAR_RENTAL_COMPANY_CAR 테이블과 CAR_RENTAL_COMPANY_RENTAL_HISTORY 테이블과 CAR_RENTAL_COMPANY_DISCOUNT_PLAN 테이블에서 자동차 종류가 '세단' 또는 'SUV' 인 자동차 중 2022년 11월 1일부터 2022년 11월 30일까지 대여 가능하고 30일간의 대여 금액이 50만원 이상 200만원 미만인 자동차에 대해서 자동차 ID, 자동차 종류, 대여 금액(컬럼명: FEE) 리스트를 출력하는 SQL문을 작성해주세요. 결과는 대여 금액을 기준으로 내림차순 정렬하고, 대여 금액이 같은 경우 자동차 종류를 기준으로 오름차순 정렬, 자동차 종류까지 같은 경우 자동차 ID를 기준으로 내림차순 정렬해주세요. SELECT a.CAR_ID, a.CA..
-
12/6스파르타/TIL(Today I Learned) 2023. 12. 6. 18:25
오늘도 어김없이 프로그래머스를 푼다. 오늘은 놀랍게도 한 문제에 거의 3시간을 쏟은거 같은데 "아 뭔가 좀만 더 하면 풀 수 있을거 같은데" 라는 생각에 3시간 잡아먹고 못풀었따 ㅎ 문제 : MEMBER_PROFILE와 REST_REVIEW 테이블에서 리뷰를 가장 많이 작성한 회원의 리뷰들을 조회하는 SQL문을 작성해주세요. 회원 이름, 리뷰 텍스트, 리뷰 작성일이 출력되도록 작성해주시고, 결과는 리뷰 작성일을 기준으로 오름차순, 리뷰 작성일이 같다면 리뷰 텍스트를 기준으로 오름차순 정렬해주세요. 이 문제에서 내가 실수한 부분은 문제를 이해 못해서 자꾸 뻘짓을 하였다 ㅠ 예시 답안을 보면 리뷰를 가장 많이 작성한 회원의 리뷰를 조회해야한다. RANK함수에 COUNT를 사용하니 최고로 많이 작성한 사람은 ..
-
프로그래머스_즐겨찾기가 가장 많은 식당 정보 출력하기스파르타/TIP 2023. 11. 30. 14:45
문제 : REST_INFO 테이블에서 음식종류별로 즐겨찾기수가 가장 많은 식당의 음식 종류, ID, 식당 이름, 즐겨찾기수를 조회하는 SQL문을 작성해 주세요. 이때 결과는 음식 종류를 기준으로 내림차순 정렬해 주세요. 문제를 보고 아래와 같이 쉽게 코딩을 하였다. SELECT FOOD_TYPE , REST_ID , REST_NAME , max(FAVORITES) FROM REST_INFO GROUP BY FOOD_TYPE ORDER BY FOOD_TYPE desc1 바로 틀려버렸다....! 분명 나의 머릿속에는 음식 종류 ( food_ type) 별 즐겨찾기가 많은 순(max(favorites))을 하면 답이 나올 거라고 생각했다. 하지만 이는 매우 1차원적인 생각이었다. 질문하기 버튼을 눌러 나의 문..
-
프로그래머스 - 루시와 엘라 찾기스파르타/TIP 2023. 11. 29. 16:22
동물 보호소에 들어온 동물 중 이름이 Lucy, Ella, Pickle, Rogan, Sabrina, Mitty인 동물의 아이디와 이름, 성별 및 중성화 여부를 조회하는 SQL 문을 작성해주세요. 매우 쉬운 문제라고 생각하고 다음과 같이 코딩을 하였다. SELECT ANIMAL_ID ,NAME ,SEX_UPON_INTAKE from animal_ins where name regexp 'Lucy|Ella|Pickle|Rogan|Sabrina|Mitty' order by 1 놀랍게도 결과는 틀렸다! 그래서 질문하기를 찾아보니 어떤 대단한 분이 설명을 기똥차게 해놓았다. REGEXP 이놈의 검색 특징은 문자열 내부에 어떤 부분이든 해당 정규식이 존재하면 TRUE가 나온다. 즉 이름이 I'M Lucy라고 써있어..
-
MYSQL 소소한 팁스파르타/TIP 2023. 11. 28. 15:36
MYSQL에서는 ISNULL을 못쓴다 코딩테스트 연습을 하는 와중에 책에서 배운 ISNULL을 쓰면 되는데 자꾸 오류가 나서 구글에 검색해 보니 IFNULL을 써야 MYSQL에서 작동한다 날짜의 차이를 구하는 함수 : datediff() select문에서 날짜 두개 써서 -로 하고 있으면 절대 안나온다 현재의 시간을 구하는 함수 : now() datediff( now() , 뺴 줄 날짜) = 날짜의 차이를 구할 수 있다 IN과 REGEXP IN은 다중연산자로 OR의 의미를 가지고 있다 그래서 문제였던 '자동차 종류별 특정 옵션이 포함된 자동차 수 구하기'의 조건을 구하는 와중 자꾸 빈 공백의 데이터만 출력이 되었다. 분명 내가 아는 것이 맞고 조건도 맞게 썼는데 왜 안 나오지?라는 생각만 가득이었다 결국..