// 20과 29사이 검색
SELECT COUNT(USER_ID) AS USERS FROM USER_INFO WHERE (AGE BETWEEN 20 AND 29) AND JOINED LIKE '%2021%';
// 앞 두자리 만 출력
SELECT
LEFT(PRODUCT_CODE, 2) AS CATEGORY,
COUNT(*) AS PRODUCTS
FROM PRODUCT
GROUP BY CATEGORY
ORDER BY CATEGORY;
//2022-05월인 진단자를 조회하는 쿼리
SELECT
MCDP_CD AS "진료과 코드",
COUNT(DISTINCT PT_NO) AS "5월예약건수"
FROM APPOINTMENT
WHERE TO_CHAR(APNT_YMD, 'YYYY-MM') = '2022-05'
GROUP BY MCDP_CD
ORDER BY COUNT(DISTINCT PT_NO) ASC, MCDP_CD ASC;
// NULL 값이면 COALESCE()로 NONE으로 바꿔준다.
SELECT
PT_NAME,
PT_NO,
GEND_CD,
AGE,
COALESCE(TLNO, 'NONE') AS TLNO
FROM PATIENT
WHERE AGE <= 12 AND GEND_CD = 'W'
ORDER BY AGE DESC, PT_NAME ASC;