출처: https://astrocosmos.tistory.com/202 [ASTROCOSMOS:티스토리] 'mysql' 태그의 글 목록 (2 Page) :: 하나둘셋넷
728x90

프로그래머스_12세 이하인 여자 환자 목록 출력하기

 

 

SELECT PT_NAME, 
        PT_NO, 
        GEND_CD, 
        AGE, 
        IFNULL(TLNO, 'NONE') as TLNO
        
    FROM PATIENT
    
    WHERE AGE<= 12 AND GEND_CD = 'W'
    
    ORDER BY AGE DESC, PT_NAME;

 

728x90
728x90

SQL 이론] ORDER BY, WHERE

 

정렬 X

SELECT * FROM TABLE1;

 

오름차순

SELECT * FROM TABLE1 ORDER BY COLUMN1 ASC;

 

오름차순 ASC 생략

SELECT * FROM TABLE1 ORDER BY COLUMN1;

 

내림차순

SELECT * FROM TABLE1 ORDER BY COLUMN1 DESC;

 

여러 컬럼 기준

SELECT * FROM TABLE1 ORDER BY COLUMN1 ASC, COLUMN2 ASC;

 

조건식 적용

SELECT * FROM TABLE1 WHERE CONDITION1 ORDER BY COLUMN1

 

컬럼 번호로 정렬

SELECT * FROM TABLE1 WHERE CONDITION1 ORDER BY 1 DESC, 2 ASC

 

728x90

+ Recent posts