-
[SQL] 짝수와 홀수인 조건으로 조회하기Data Analysis/SQL 2023. 12. 16. 12:24
Table of Contents
- Question
- Answer
- Reference
Question
Query a list of CITY names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer.
The STATION table is described as follows:where LAT_N is the northern latitude and LONG_W is the western longitude.
Answer
Question quest us how to query the City names that have an even ID number. So, We use "Condition Filtering" and mod function.
MYSQL :
SELECT DISTINCT CITY FROM STATION WHERE ID % 2 = 0;
ORACLE:
SELECT DISTINCT CITY FROM STATION WHERE MOD(ID, 2) = 0 ;
Reference
"Arithmetic Operators", MySQL, https://dev.mysql.com/doc/refman/8.2/en/arithmetic-functions.html
"MOD", Oracle, https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/MOD.html
Revising the Select Query", hackerrank, https://www.hackerrank.com/challenges/revising-the-select-query/
'Data Analysis > SQL' 카테고리의 다른 글
[SQL] 조건문을 활용한 특정 칼럼 조회하기 (1) 2023.12.15 [SQL] 조건문을 활용한 모든 데이터 조회하기 (1) 2023.12.10 [SQL] 날짜 함수를 이용하여 특정 기간 데이터 조회하기 (4) 2023.06.16 [SQL] Windows에서 MariaDB root 계정 분실 시 (2) 2023.04.05 [SQL] SQL(Structured Query Language)이란? (2) 2023.03.23