[TIL][SQL] SELECT-04

asgowon·2020년 10월 28일
0

SQL

목록 보기
5/10

2개 혹은 그 이상의 Column들을 1개의 Column으로 출력하고 싶다면?

||(Concatenation)을 사용하면 된다.

예시를 통해 설명한다.

SQL> SELECT ename||'''s job is '||job
  2  FROM emp ;

ENAME||'''SJOBIS'||JOB
-----------------------------
SMITH's job is CLERK
ALLEN's job is SALESMAN
WARD's job is SALESMAN
JONES's job is MANAGER
MARTIN's job is SALESMAN
BLAKE's job is MANAGER
CLARK's job is MANAGER
SCOTT's job is ANALYST
KING's job is PRESIDENT
TURNER's job is SALESMAN
ADAMS's job is CLERK
JAMES's job is CLERK
FORD's job is ANALYST
MILLER's job is CLERK

한 column으로 보이지 않을 수 있다.
그래서 alias(별칭을 사용해보았다.)
별칭이 기억나지 않는다면? → alias(별칭) 링크

SQL> SELECT ename||'''s job is '||job "하나의 COLUMN"
  2  FROM emp;

하나의 COLUMN
-----------------------------
SMITH's job is CLERK
ALLEN's job is SALESMAN
WARD's job is SALESMAN
JONES's job is MANAGER
MARTIN's job is SALESMAN
BLAKE's job is MANAGER
CLARK's job is MANAGER
SCOTT's job is ANALYST
KING's job is PRESIDENT
TURNER's job is SALESMAN
ADAMS's job is CLERK
JAMES's job is CLERK
FORD's job is ANALYST
MILLER's job is CLERK

이 방법을 백업/복구 관련 작업이나 관리 및 튜닝 작업할 때 자주 사용한다고 한다.

profile
goaswon

0개의 댓글