SQL
문제 50.
FOOD_PRODUCT와 FOOD_ORDER 테이블에서 생산일자가 2022년 5월인 식품들의 식품 ID, 식품 이름, 총매출을 조회하는 SQL문을 작성해주세요. 이때 결과는 총매출을 기준으로 내림차순 정렬해주시고 총매출이 같다면 식품 ID를 기준으로 오름차순 정렬해주세요.
SELECT p.product_id, p.product_name, p.price*o.amount as TOTAL_SALES
from food_product p join food_order o on p.product_id=o.product_id
where o.produce_date like '2022-05%'
order by 3 desc, 1
SELECT p.product_id, p.product_name, sum(p.price*o.amount) as TOTAL_SALES
from food_product p join food_order o on p.product_id=o.product_id
where o.produce_date like '2022-05%'
group by 1
order by 3 desc, 1
총.총매출..
문제 51.
천재지변으로 인해 일부 데이터가 유실되었습니다. 입양을 간 기록은 있는데, 보호소에 들어온 기록이 없는 동물의 ID와 이름을 ID 순으로 조회하는 SQL문을 작성해주세요
SELECT animal_id,name
from animal_outs
except
select animal_id,name
from animal_ins
order by 1
order by 맨 뒤에. select 컬럼명은 동일해야..
문제 52.
상반기 아이스크림 총주문량이 3,000보다 높으면서 아이스크림의 주 성분이 과일인 아이스크림의 맛을 총주문량이 큰 순서대로 조회하는 SQL 문을 작성해주세요.
SELECT i.flavor
from first_half f join icecream_info i on f.flavor=i.flavor
where f.total_order>3000 and i.flavor in ('strawberry','melon')
order by f.total_order desc
문제 53.복습
ONLINE_SALE 테이블에서 동일한 회원이 동일한 상품을 재구매한 데이터를 구하여, 재구매한 회원 ID와 재구매한 상품 ID를 출력하는 SQL문을 작성해주세요. 결과는 회원 ID를 기준으로 오름차순 정렬해주시고 회원 ID가 같다면 상품 ID를 기준으로 내림차순 정렬해주세요.
SELECT user_id, product_id
from online_sale
group by 1,2
having count(*)>1
order by 1,2 desc
도무지무지. . 그룹바이 두개 이상도 가능쿠나.. 해빙도 공부. 하셈.
문제 54.
가장 최근에 들어온 동물은 언제 들어왔는지 조회하는 SQL 문을 작성해주세요.
SELECT max(datetime)
from animal_ins
문제 55.
USED_GOODS_BOARD와 USED_GOODS_USER 테이블에서 중고 거래 게시물을 3건 이상 등록한 사용자의 사용자 ID, 닉네임, 전체주소, 전화번호를 조회하는 SQL문을 작성해주세요. 이때, 전체 주소는 시, 도로명 주소, 상세 주소가 함께 출력되도록 해주시고, 전화번호의 경우 xxx-xxxx-xxxx 같은 형태로 하이픈 문자열(-)을 삽입하여 출력해주세요. 결과는 회원 ID를 기준으로 내림차순 정렬해주세요.
SELECT b.writer_id, u.nickname, concat(u.street_address1,u.street_address2) as '전체주소', format(tlno,'###-####-####')
from used_goods_board b join used_goods_user u on b.writer_id=u.user_id
group by 1
having count(b.board_id)>2
SELECT b.writer_id, u.nickname, concat(u.street_address1,u.street_address2) as '전체주소'
, concat(left(tlno,3),'-',mid(tlno,4,4),'-',concat(right(tlno,4))
from used_goods_board b join used_goods_user u on b.writer_id=u.user_id
group by 1
having count(b.board_id)>2
SELECT b.writer_id, u.nickname, concat(u.city,' ',u.street_address1,' ',u.street_address2) as '전체주소'
,concat(substr(tlno,1,3),'-',substr(tlno,4,4),'-',substr(tlno,8)) as '전화번호'
from used_goods_board b join used_goods_user u on b.writer_id=u.user_id
group by 1
having count(b.board_id)>2
order by u.user_id desc
concat, substr 복습필. 그리고 블로그 보니 더 간단한 풀이들이. with, 서브쿼리 등등 사용. 내껀 넘 지저분 합니다.
sql 설치 실행 성공
튜터님의 1시간 미만은 혼자 20시간을 이긴다.! 백지장과 그 두꺼운 책.. 나도 책이 되어야지..
비밀번호.. 잘 알아야..
홈브류와 사이트 번갈아 설치.. 오류의 지름길.. 오하하..
cd /etc/mysql
cd /etc
ls -al
vim my.cnf
[mysqld]
:wq
:q!
등등등.. 사용.. 다음에..또.. 글타면...등등..
240112금_TIL (0) | 2024.01.12 |
---|---|
240111목_TIL (1) | 2024.01.11 |
240109화_TIL (1) | 2024.01.09 |
240108월_TIL (0) | 2024.01.08 |
240105금_TIL (1) | 2024.01.05 |