Skip to Content
SQL 시작하기
book

SQL 시작하기

by Thomas Nield
May 2025
Beginner to intermediate
134 pages
1h 46m
Korean
O'Reilly Media, Inc.
Content preview from SQL 시작하기

5장. 어디

이 작품은 AI를 사용하여 번역되었습니다. 여러분의 피드백과 의견을 환영합니다: translation-feedback@oreilly.com

앞으로 몇 장에 걸쳐 SELECT 문에 더 많은 기능을 추가할 것입니다. 데이터 작업 시 매우 일반적인 작업은 기준에 따라 레코드를 필터링하는 것으로, WHERE 문을 사용하여 수행할 수 있습니다.

더 많은 함수를 배우고 WHERE 절에서 사용할 예정이지만, 이전 장에서 설명한 대로 SELECT 문에서도 사용할 수 있습니다. 대부분의 경우 표현식과 함수는 SQL 문의 어느 부분에서나 사용할 수 있습니다.

레코드 필터링

weather_stations 이라는 다른 데이터베이스를 열겠습니다. 이 데이터베이스를 데이터베이스 탐색기에 추가합니다(이 작업을 잊어버렸다면 3장 참조). 데이터베이스를 더블클릭하면 STATION_DATA 이라는 단일 테이블이 표시됩니다. 여기에는 다양한 기상 관측소에서 수집한 날씨 관련 샘플 데이터가 포함되어 있습니다.

모든 열에 SELECT 을 실행하여 내부 데이터를 확인합니다:

SELECT * FROM station_data;

여기에는 약 28,000개의 레코드에 달하는 많은 데이터가 있습니다(그림 5-1). 이러한 레코드를 하나씩 스크롤하는 것으로는 흥미로운 정보를 많이 얻을 수 없습니다. 이 데이터를 의미 있는 것으로 변환하려면 몇 가지 SQL 기능을 더 배워야 합니다. 우선 기준에 따라 레코드를 필터링하는 데 사용할 수 있는 WHERE 문을 배워보겠습니다.

The weather_stations database
그림 5-1. weather_stations 데이터베이스
참고

테이블 이름과 열은 대문자 또는 소문자로 정의할 수 있습니다. SELECT , FROM, WHERE 와 같은 SQL 명령 은 대문자 또는 소문자로도 사용할 수 있습니다.

숫자에서 WHERE 사용

2010년에 대한 station_data 레코드에만 관심이 있다고 가정해 보겠습니다. 이와 같은 간단한 기준의 경우 WHERE 을 사용하면 매우 간단합니다. 이 쿼리를 사용하면 year 필드가 2010 와 같은 레코드만 반환해야 합니다(그림 5-2):

SELECT * FROM station_data
WHERE year = 2010;
Records for the year 2010
그림 5-2. 2010년 한 해 동안의 기록

반대로 != 또는 <> 을 사용하여 2010년을 제외한 모든 을 로 가져올 수 있습니다. 예를 들어

SELECT * FROM station_data
WHERE year != 2010

또는:

SELECT * FROM station_data
WHERE year <> 2010

이 두 구문은 동일한 기능을 수행합니다. SQLite와 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Oracle Database 11g Release 2 Performance Tuning Tips & Techniques

Oracle Database 11g Release 2 Performance Tuning Tips & Techniques

Richard Niemiec

Publisher Resources

ISBN: 9798341656307