TIL (3) 기록

UihyunLee·2025년 4월 9일

Sql

Select, group by, order by 등 다양한 sql 문법이 있고 오늘 수업을 들어보며 다시 한번 복습하는 시간을 가졌다.

select restaurant_name "원래 상점명",
       replace(restaurant_name, 'Blue', 'Pink') "바뀐 상점명"
from food_orders
where restaurant_name like '%Blue Ribbon%'

select addr "원래 주소",
       substr(addr, 1, 2) "시도"
from food_orders
where addr like '%서울특별시%'

select restaurant_name "원래 이름",   
       addr "원래 주소",
       concat('[', substring(addr, 1, 2), '] ', restaurant_name) "바뀐 이름"
from food_orders
where addr like '%서울%'

select cuisine_type "타입", AVG(price) "평균 금액", SUBSTR(addr, 1,2) "지역"
from food_orders
where addr LIKE "%서울%"
group by 1,3

select * from customers;

select substr(email, 10) "도메인",
count(1) "고객수",AVG(age) "평균연령"
from customers
group by substr(email, 10);

select concat('[', SUBSTR(addr,1,2), ']', restaurant_name, ' (', cuisine_type, ')') "음식점", count(1) "주문건수"
from food_orders
group by 1;

select restaurant_name,
       cuisine_type "원래 음식 타입",
       if(cuisine_type='Korean', '한식', '기타') "음식 타입"
from food_orders

select addr "원래 주소",
       if(addr like '%평택군%', replace(addr, '문곡리', '문가리'), addr) "바뀐 주소"
from food_orders
where addr like '%문곡리%'

select substring(if(email like '%gmail%', replace(email, 'gmail', '@gmail'), email), 10) "이메일 도메인",
       count(customer_id) "고객 수",
       avg(age) "평균 연령"
from customers
group by 1

select order_id,
       price,
       quantity,
       case when quantity=1 then price
            when quantity>=2 then price/quantity end "음식 단가"
from food_orders

IOC

IOC란 무엇인가?
Inversion of Control의 줄임말로 한글로 번역하면 제어의 역전이다.
개발에서 생각하자면 개발자가 의존 객체를 직접 만드는 것이 아닌, 외부에서 받아 사용하는 것을 뜻함.
그렇기 때문에 제어가 역전이 되기에 Ioc라고 한다.

DI

DI는 Dependency Injection으로 의존관계 주입이라고한다.
DI 컨테이너 : 구현 객체를 생성하고 주입해주는 별도의 설정 클래스

사실 아직 명확하게는 감이 안온다. 확장 혹은 유지보수를 할 때 최소한의 수정을 하기 위해서 DI 컨테이너를 만든다..라고 생각이 드는데 조금더 확실하게 용어 정리를 해야할 필요가 있을 것 같다.

profile
공부 기록

0개의 댓글