반응형

 

원래 데이터

나이 구하기

select 2023-birthYear as koreanAge 
from players
where deathYear is null and birthYear is not null
order by koreanAge

 

 

 

쿼리 순서는 

 

from

where

select

orderby 

순 이기 때문에 위에서 쓰여진 네이밍을 해당 명령 포함 하단에서 쓸 수 있다

 

이런 경우엔 에러가 나는것을 알 수 있다

 

 

 

그래서 이렇게 다시 한번 birthYear 를 써서 연산해야한다

select 2023-birthYear as koreanAge 
from players
where deathYear is null and birthYear is not null and (2023-birthYear <= 80 )
order by koreanAge

 

 

 

 

 

 

그 외 일반적인 규칙들

  1. select 3-NULL 의 결과는 NULL 이다
  2. 정수 나누기 정수는 수학적으로 소수로 떨어진다해도 정수고
  3. 분모를 소수로 .0 처리해주면 소수로 나온다
  4. 0 으로 나누면 오류가 난다
  5. ROUND, POWER, COS 함수등들도 제공된다

 

그 외 연산들 참고 

https://learn.microsoft.com/en-us/sql/t-sql/functions/mathematical-functions-transact-sql?view=sql-server-ver16 

 

Mathematical Functions (Transact-SQL) - SQL Server

Mathematical Functions (Transact-SQL)

learn.microsoft.com

 

반응형

+ Recent posts