SQL

SELECT/FROM/LIMIT + 해커랭크 예제

얆생 2023. 6. 20. 10:49
  • 모든 데이터 가져오기
SELECT *
FROM 테이블명

예제: https://www.hackerrank.com/challenges/select-all-sql/problem?isFullScreen=true 

 

Select All | HackerRank

Query all columns for every row in a table.

www.hackerrank.com

Q: Query all columns (attributes) for every row in the CITY table.

The CITY table is described as follows:

A: 

SELECT *
FROM city

!! 가독을 위해 명령어는 대문자로, 테이블명이나 칼럼명은 소문자로 써준다.

 

 

 

  • 특정 칼럼의 데이터 가져오기
SELECT 칼럼명1, 칼럼명2, ...
FROM 테이블명

예제: https://www.hackerrank.com/challenges/weather-observation-station-1/problem?isFullScreen=true

 

Weather Observation Station 1 | HackerRank

Write a query to print the CITY and STATE for each attribute in the STATION table.

www.hackerrank.com

Q: Query a list of CITY and STATE from the STATION table.
The STATION table is described as follows:

A:

SELECT city, state
FROM station

 

 

 

  • 데이터 샘플만 간단히 확인할 때
SELECT * 또는 칼럼명
FROM 테이블명
LIMIT 10

  10개만 뽑아오는 경우