일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- django
- math
- 파이썬
- Mac
- Redshift
- Python
- PySpark
- dataframe
- gas
- Google Spreadsheet
- matplotlib
- array
- GIT
- Apache
- Kotlin
- Java
- Google Excel
- Excel
- PostgreSQL
- Tkinter
- numpy
- string
- list
- c#
- PANDAS
- hive
- SQL
- Github
- google apps script
- Today
- Total
목록SQL/Redshift (78)
달나라 노트
datediff(단위, start_date, end_date) datediff 함수는 위처럼 사용할 수 있습니다. datediff 함수는 start_date에서 end_date 간의 차이값을 명시한 단위로 반환해주죠. 정확히 말하면 end_date - start_date의 결과를 명시한 단위의 수치로 나타내줍니다. 따라서 start_date end_date 일 경우 결과값은 음수일 것입니다. select datediff(day, to_date('20210101', 'yyyymmdd'), to_date('20210110', 'yyyymmdd')) -> 9 select datediff(day, to_date('20210110', 'y..
to_char(date_timestamp, format) to_char는 위처럼 2개의 parameter를 받습니다. date_timestamp = 날짜 데이터나 timestamp 데이터를 의미합니다. format = date_timestamp를 문자로 변환할 때 어떠한 형식으로 변환할지를 나타냅니다. select sysdate; - Output 2021-01-22 15:24:48.315132 select current_date; - Output 2021-01-22 Redshift에선 sysdate를 이용해 현재 시점의 날짜, 시간 데이터를 얻을 수 있고, current_date를 통해 오늘 날짜를 얻을 수 있습니다. 이를 이용해서 to_char를 테스트해보겠습니다. select to_char(sysda..
to_date(date_str, date_format) to_date는 위처럼 2개의 parameter를 받습니다. date_str = 날짜를 의미하는 텍스트(이 값의 date type은 날짜가 아닙니다.) date_format = date_str의 날짜 format 바로 한번 예시를 봅시다. select to_date('20210121', 'yyyymmdd') as date; select to_date('2021-01-21', 'yyyy-mm-dd') as date; select to_date('2021/01/21', 'yyyy/mm/dd') as date; select to_date('01-21-2021', 'mm-dd-yyyy') as date; select to_date('01/21/2021', ..
cast(value_or_column as data_type) convert(data_type, value_or_column) cast와 convert는 어떤 값 또는 컬럼에 있는 값들을 원하는 data type으로 바꿔줍니다. select cast(1 as varchar); select convert(varchar, 1); select cast('1' as int); select convert(int, '1'); 위 select 구문의 결과는 모두 1입니다. 하지만 처음 2개의 select로부터 반환되는 1은 텍스트이며, 세 번재, 네 번째 select로부터 반환되는 1은 정수입니다. select 1::varchar; select '1'::int; 추가로 위처럼 2개의 콜론을 사용하여 data type..