코딩/SQL

TIL(2023.03.14) - SQL 배운 내용(데이터 조합)

AMD만세 2023. 3. 14. 19:59

1. 오늘 배운 내용

select discount_class_cd_id
, (
select a.minor_name
from minor_codes a
, major_codes b
where a.major_code_id = b.major_code_id
and b.major_code = 'discount_class'
and a.use_yn = 'Y'
and b.use_yn = 'Y'
and b.account_id = 1
and a.minor_id = discount_class_cd_id
) as discount_class_name
, from_date
, to_date
, from_time
, to_time
-- 영업구분 ??
, day_scd
, ( select name from s_codes where group_name = 'day' and code = day_scd ) as day_name
, apply_amt -- 정상금액인지 할인금액인지 ??
, discount_remark -- 할인내용
, gd.created_id
, ( select a.user_name from admins a where a.admin_code = gd.created_id) as created_name
, gd.created_at
from green_fee_discounts gd
;

1)  -- : 주석

2) green_fee_discounts gd : green_fee_discounts를 gd라 하겠다.(치환)

3) 위 내용은, 

    다른 테이블에 있는 값을 가져와서

    조합하는 과정이다.

4) day_scd
, ( select name from s_codes where group_name = 'day' and code = day_scd ) as day_name

-> day_scd 값을 group_name이 day 이고

                          code가 day_scd 값을 지닌

                          s_codes 테이블에서

                          name 값을 가져와서

                          day_name에 저장한다.

 

 

 

'코딩 > SQL' 카테고리의 다른 글

TIL(2023.03.07) - SQL 문법 주의사항(feat. xml)  (0) 2023.03.07