본문 바로가기

SQL

(6)
SQL 1주차 라이브세션 과제 (1~3회) (작성중) 1회차/*문제1 date 컬럼이 2023-01-01 보다 큰 날짜의 game_account_id, game_actor_id, serverno를 추출해주세요.*/select game_account_id, game_actor_id, serverno, datefrom users uwhere date > '2023-01-01'  /*문제2 level > 10, * serverno !=1 * etc_str2='레벨업 패키지' or '시즌패스' * etc_str1 '상점에서 구매' * date, ip_addr, exp, zone_id 조회 date 기준 내림차순 */select date, ip_addr, exp, zone_idfrom users u where serverno > 1and etc_str..
SQL 피벗 테이블 ( 드디어!!) 이게 보니까 결국 max( ) 를 써야 한다는 상황을 알아야 해결이 되더라.그리고 내가 쓰려는 데이터는 from 테이블에서 조회를 해서 가져와야지 쓸 수 있더라 #음식 타입별, 연령별 주문건수 SELECT a.cuisine_type '유형',max(if(generation='10대',cnt_gene, 0)) '10대',max(if(generation='20대',cnt_gene, 0)) '20대',max(if(generation='30대',cnt_gene, 0)) '30대',max(if(generation='40대',cnt_gene, 0)) '40대',max(if(generation='50대',cnt_gene, 0)) '50대'FROM(SELECT cuisine_type,age,case when c.age..
SQL 5주차 강의 내용 SELECT restaurant_name,    avg(rating) avg_rating,    avg(if(rating'Not given', rating, null)) avg_rating2 from food_orders f group by restaurant_name 값을 제외 select a.order_id,        a.customer_id,        a.restaurant_name,        a.price,        b.name,        b.age,        b.gender from food_orders a left join customers b on a.customer_id=b.customer_id where b.customer_id is not null  값의 변경 se..
SQL 3주차 주문 테이블에서 주문수량량 1건의 주문건의 음식 가격의 평균을 음식종류별로 조회하여 음식 가격이 높은 순서대로 정렬하기 select cuisine_type "음식종류" , avg(price) "평균가격" from food_orders fo  where quantity = 1 group by cuisine_type  order by avg(price) desc SELECT CONCAT('[',SUBSTR(addr, 1, 2),"]",restaurant_name,'-',cuisine_type) "음식점", count(1) '총 주문건수' from food_orders fo  group by 1 #addr = 지역(시도) restauant_name = 음식점 이름, cuisine_type = 음식종류     ..
SQL 2주 #음식 종류별로 가장 높은 주문 금액과 가장 낮은 주문금액을 조회하고, 가장 낮은 주문금액순으로 정렬하기 SELECT cuisine_type, max(price) max_price, min(price) min_price from food_orders fo  group by cuisine_type  order by min(price) desc
SQL 1주차 selct * from table SELECT order_id ord_no, price "가격", quantity "수량" from food_orders fo  select name "이름",  email "e-mail" from customers c SELECT restaurant_name '식당명', customer_id '고객번호' FROM food_orders fo where food_preparation_time between 20 and 30 and cuisine_type ='Korean'