두 개 이상의 테이블을 결합하여 여러 행을 검색하는 것입니다.

 

SELECT * FROM weather JOIN cities ON (weather.city = cities.name);

실행 결과

 

JOIN TYPE

 

 

SELECT * FROM weather LEFT OUTER JOIN cities ON (weather.city = cities.name);

LEFT JOIN 실행 결과

SELECT CURRENT_USER, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP;

실행 결과

 

이번달의 첫번째 날과 마지막 날 구하기 입니다.

 

SELECT cast(date_trunc('month',current_date) as date) as firstday, (date_trunc('MONTH', current_date) + INTERVAL '1 MONTH - 1 day')::date lastday;

실행 결과

 

SELECT (last_name || '_' || first_name) AS full_name, last_name, first_name FROM employees

실행 예제

 

SELECT (ROW_NUMBER() OVER()) AS ROWNUM, * FROM customers limit 10

실행 예제1

 

 

SELECT * FROM customers limit 10

실행 예제2

 

1개의 기본키를 가지는 테이블 생성하기.

CREATE TABLE COMPANY
(
	ID      INT PRIMARY KEY NOT NULL,
	NAME    TEXT				NOT NULL,
	AGE     INT					NOT NULL,
	ADDRESS CHAR(50),
	SALARY  REAL
);

 

+ Recent posts