3월 4주차

canugo·2023년 3월 20일
0

해커랭크

목록 보기
12/12

Weather Observation Station 10

문제

Query the list of CITY names from STATION that do not end with vowels. Your result cannot contain duplicates.

Input Format

The STATION table is described as follows:

문제풀이 & 해석

STATION에서 모음으로 끝나지 않는 CITY 이름 목록을 쿼리합니다. 결과에 중복 항목이 포함될 수 없습니다.

SELECT DISTINCT CITY ➡ CITY이름 을 중복되지 않게 골라라 
FROM STATION ➡ STATION 테이블로부터
WHERE CITY NOT LIKE '%A'➡ 끝자리가 A, E , I , O, U가 아닌
AND CITY NOT LIKE '%E'
AND CITY NOT LIKE '%I'
AND CITY NOT LIKE '%O'
AND CITY NOT LIKE '%U'

Weather Observation Station 11

문제

Query the list of CITY names from STATION that either do not start with vowels or do not end with vowels. Your result cannot contain duplicates.

Input Format

The STATION table is described as follows:

문제풀이 & 해석

STATION에서 모음으로 시작하지 않거나 모음으로 끝나지 않는 도시 이름 목록을 쿼리합니다. 결과에 중복 항목이 포함될 수 없습니다.

SELECT DISTINCT CITY ➡ CITY이름 을 중복되지 않게 골라라 
FROM STATION ➡ STATION 테이블로부터
WHERE 
((CITY NOT LIKE '%A' ➡ 끝자리가 A, E , I , O, U가 아닌
AND CITY NOT LIKE '%E'
AND CITY NOT LIKE '%I'
AND CITY NOT LIKE '%O'
AND CITY NOT LIKE '%U')
OR ➡ 또는
(CITY NOT LIKE 'A%' ➡ A, E , I , O, U로 시작하지 않는 
AND CITY NOT LIKE 'E%'
AND CITY NOT LIKE 'I%'
AND CITY NOT LIKE 'O%'
AND CITY NOT LIKE 'U%'))

Weather Observation Station 12

문제

Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot contain duplicates.

문제풀이 & 해석

SELECT DISTINCT CITY ➡ CITY이름 을 중복되지 않게 골라라 
FROM STATION ➡ STATION 테이블로부터
WHERE 
((CITY NOT LIKE '%A' ➡ A, E , I , O, U로 시작하지 않는
AND CITY NOT LIKE '%E'
AND CITY NOT LIKE '%I'
AND CITY NOT LIKE '%O'
AND CITY NOT LIKE '%U')
AND ➡ 그리고
(CITY NOT LIKE 'A%' ➡ A, E , I , O, U로 시작하지 않는
AND CITY NOT LIKE 'E%'
AND CITY NOT LIKE 'I%'
AND CITY NOT LIKE 'O%'
AND CITY NOT LIKE 'U%'))

Higher Than 75 Marks

문제

Query the Name of any student in STUDENTS who scored higher than Marks. Order your output by the last three characters of each name. If two or more students both have names ending in the same last three characters (i.e.: Bobby, Robby, etc.), secondary sort them by ascending ID.

설명

Only Ashley, Julia, and Belvet have Marks > . If you look at the last three characters of each of their names, there are no duplicates and 'ley' < 'lia' < 'vet'.

문제해석 & 풀이

마크보다 높은 점수를 받은 학생의 이름을 쿼리합니다. 각 이름의 마지막 세 문자를 기준으로 출력 순서를 지정합니다. 두 명 이상의 학생이 모두 같은 마지막 세 글자로 끝나는 이름을 가지고 있는 경우(예: Bobby, Robby 등), 오름차순 ID를 기준으로 보조 정렬합니다.

SELECT Name ➡ 이름을 선택해라 
FROM STUDENTS ➡ STUDENTS 테이블로부터 
WHERE Marks > 75 ➡ Marks가 75 이상인
ORDER BY RIGHT(Name, 3), ID ➡ 끝자리를 오름차순으로 

Employee Names

문제

Write a query that prints a list of employee names (i.e.: the name attribute) from the Employee table in alphabetical order.

문제풀이 & 해석

직원 테이블의 직원 이름 목록(예: 이름 속성)을 알파벳 순서로 인쇄하는 쿼리를 작성합니다.

SELECT NAME FROM EMPLOYEE ORDER BY NAME ➡ EMPLOYEE 테이블에서 NAME순으로 정렬

Employee Salaries

문제

Write a query that prints a list of employee names (i.e.: the name attribute) for employees in Employee having a salary greater than per month who have been employees for less than months. Sort your result by ascending employee_id.

문제풀이 & 해석

직원이 된 지 10개월 미만인 직원의 월급이 $2000보다 많은 직원의 직원 이름 목록(즉, 이름 속성)을 인쇄하는 쿼리를 작성합니다. employee_id를 오름차순으로 정렬합니다.

SELECT NAME FROM EMPLOYEE ➡ NAME을 선택해라 EMPLOYEE테이블에서
WHERE SALARY > 2000 ➡ 월급이 2000이상이고
AND MONTHS < 1010개월 미만인
ORDER BY EMPLOYEE_ID ➡ EMPLOYEE_ID순으로 정렬해라 

Type of Triangle

문제

Write a query identifying the type of each record in the TRIANGLES table using its three side lengths. Output one of the following statements for each record in the table:

  • Equilateral: It's a triangle with sides of equal length.
  • Isosceles: It's a triangle with sides of equal length.
  • Scalene: It's a triangle with sides of differing lengths.
  • Not A Triangle: The given values of A, B, and C don't form a triangle.

문제풀이 & 해석

삼각형 테이블에서 각 레코드의 세 변 길이를 사용하여 각 레코드의 유형을 식별하는 쿼리를 작성합니다. 표의 각 레코드에 대해 다음 문 중 하나를 출력합니다

  • Equilateral: 세 변의 길이가 모두 같은 삼각형(정삼각형)
  • Isosceles: 이등변 삼각형
  • Scalene: 세 변의 길이가 모두 다른 삼각형
  • Not A Triangle: A, B, C의 주어진 값은 삼각형을 형성하지 않는다.
SELECT 
CASE
    WHEN A = B AND B = C AND C = A THEN "Equilateral"
    WHEN A + B <= C THEN "Not A Triangle"
    WHEN A != B AND B != C AND A != C THEN "Scalene"
    ELSE "Isosceles"
END AS A
FROM TRIANGLES

⭐The PADS

문제

Generate the following two result sets:

Query an alphabetically ordered list of all names in OCCUPATIONS, immediately followed by the first letter of each profession as a parenthetical (i.e.: enclosed in parentheses). For example: AnActorName(A), ADoctorName(D), AProfessorName(P), and ASingerName(S).
Query the number of ocurrences of each occupation in OCCUPATIONS. Sort the occurrences in ascending order, and output them in the following format:

There are a total of [occupation_count][occupation]s.
where [occupation_count] is the number of occurrences of an occupation in OCCUPATIONS and [occupation] is the lowercase occupation name. If more than one Occupation has the same [occupation_count], they should be ordered alphabetically.

Note: There will be at least two entries in the table for each type of occupation.

문제풀이 & 해석

알파벳 순으로 정렬된 직업의 모든 이름 목록을 조회하고,
각 직업의 첫 글자를 괄호로 묶습니다.
예: 배우 이름(A), 의사 이름(D), 교수 이름(P) 및 가수 이름(S).
Occupations에서 각 직업의 발생 횟수를 쿼리합니다.
발생 횟수를 오름차순으로 정렬하고 다음 형식으로 출력합니다

0개의 댓글