MySQL

SQL

HackerRank SQL 3문제 풀이 (3)

1. Weather Observation Station 3 https://www.hackerrank.com/challenges/weather-observation-station-3/problem?isFullScreen=true Weather Observation Station 3 | HackerRankQuery a list of unique CITY names with even ID numbers.www.hackerrank.com/*짝수인 id number를 가지는 시티 네임, 중복 제외짝수는 2로 나눠지는거*/SELECt DISTINCT cityFROM stationWHERE id % 2 = 0 ↓ where절에 이렇게도 쓸 수 있음SELECt DISTINCT cityFROM stationWHERE M..

SQL

MySQL 숫자, 문자열 다루는 함수 정리

숫자를 다루는 함수ROUND(칼럼명/값, n): 값을 소수점 이하 n자릿수로 반올림TRUNCATE(칼럼명/값, n): 값을 소수점 이하 n자릿수까지 남기고 나머지 버림CEIL(칼럼명/값): 값의 소수점 이하를 올림해 정수 반환FLOOR(칼럼명/값): 값의 소수점 이하를 버림해 정수 반환 POWER(칼럼명/값, n) = POW(칼럼명/값, n): 값을 n제곱해서 반환 >> POWER(2, 3) = 8SQRT(칼럼명/값): 값의 제곱근을 반 >> SQRT(4) = 2*값의 n제곱근을 구하기 = 값의 1/n제곱을 구하기 = POWER(칼럼명/값, 1/n)>> POWER(8, 1/3) = 2 MOD(칼럼명/값, n) : 값을 n으로 나눴을 때 나머지를 반환 >> 칼럼명/값 % n >> MOD(5, 2) = 1A..

SQL

HackerRank 해커랭크 SQL(Basic) 뽀개기 (1) + LENGTH()

sql 코테 대비.. 전에 공부하면서 풀었던 문제 제외 1. https://www.hackerrank.com/challenges/weather-observation-station-9/problem?isFullScreen=true Weather Observation Station 9 | HackerRank Query an alphabetically ordered list of CITY names not starting with vowels. www.hackerrank.com Q: Query the list of CITY names from STATION that do not start with vowels. Your result cannot contain duplicates. Input Format The..

SQL

Aggregate Function 집계 함수 - COUNT/SUM/AVG/MIN/MAX

COUNT 개수를 세어줌 SELECT COUNT(* 또는 칼럼명) FROM 테이블명 Products ProductID ProductName SupplierID Price 1 A 1 18 2 A 2 19 3 B 3 Null 4 C 5 22 5 Null Null 5 - 전체 개수 세기 SELECT COUNT (*) FROM products >> 5 - ProductName 개수 세기, 유일값만 세기 SELECT COUNT(productname) FROM products >> 4 -- Null 값은 빼고 세줌 SELECT COUNT(DISTINCT productname) FROM products >> 3 -- Null값 빼고 중복 안되게 SUM 숫자 데이터를 가진 칼럼의 합을 계산해줌 SELECT SUM(칼럼..

SQL

MySQL 정규표현식 REGEXP + 해커랭크 예제 풀이

1. https://www.hackerrank.com/challenges/weather-observation-station-7/problem?isFullScreen=true Weather Observation Station 7 | HackerRank Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. www.hackerrank.com Q: Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. Your result cannot contain duplicates. Input Format The STATION table is describ..

SQL

HackerRank 해커랭크 SQL 예제 추가 풀이 (1)

1. https://www.hackerrank.com/challenges/revising-the-select-query-2/problem?isFullScreen=true Revising the Select Query II | HackerRank Query the city names for all American cities with populations larger than 120,000. www.hackerrank.com Q: Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA. The CITY table is de..