Mathematical Operators
Coddy SQL 여정의 기초 섹션에 포함된 레슨 — 72개 중 23번째.
SQL에서는 쿼리 내에서 컬럼 값을 사용하여 직접 연산을 수행할 수 있습니다. 이는 기존 데이터를 기반으로 새로운 값을 계산해야 할 때 유용합니다. 예를 들어:
나눗셈에 관한 중요한 참고 사항: SQL에서 정수를 나눌 때, 결과는 관련된 데이터 타입에 따라 달라집니다:
| 연산자 | 연산 |
|---|---|
| + | 덧셈 |
| - | 뺄셈 |
| * | 곱셈 |
| / | 나눗셈 |
SELECT price + 10 as increased_price,
price - 10 as reduced_price,
price * 10 as multiple_price,
price / 2 as half_price
FROM products;- 정수 ÷ 정수 = 정수 (버림):
7 / 2 = 3(3.5가 아님)
- Integer ÷ Float = Float:
7 / 2.0 = 3.5
- Float ÷ Integer = Float:
7.0 / 2 = 3.5
챌린지
쉬움사용 가능한 테이블 및 열:
<strong>products</strong>:<strong>id</strong>,<strong>price</strong>,<strong>quantity</strong>
두 개의 계산된 열을 만드세요:
high_mix_op라는 이름의 첫 번째 열:- price 열을 가져옵니다
- 2를 곱합니다
- 결과에서 20을 뺍니다
low_mix라는 이름의 두 번째 열:- quantity 열을 가져옵니다
- 1.5로 나눕니다
- 결과에 5를 더합니다
직접 해보기
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.
기초의 모든 레슨
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns