본문 바로가기

Algorithm & SQL/SQL22

[solvesql] SQL 문제 풀이 (5) 1. 첫 주문과 마지막 주문 select date(min(order_purchase_timestamp)) as first_order_date, date(max(order_purchase_timestamp)) as last_order_date from olist_orders_dataset; 2. 많이 주문한 테이블 찾기 select * from tips where total_bill > ( select avg(total_bill) from tips ); 2023. 2. 3.
[solvesql] SQL 문제 풀이 (4) 1. 쇼핑몰의 일일 매출액과 ARPPU select date(ood.order_purchase_timestamp) as dt, count(distinct (ood.customer_id)) as pu, round(sum(oopd.payment_value), 2) as revenue_daily, round( sum(oopd.payment_value) / count(distinct (ood.customer_id)), 2 ) as arppu from olist_orders_dataset ood join olist_order_payments_dataset oopd on ood.order_id = oopd.order_id where ood.order_purchase_timestamp >= '2018-01-01' g.. 2023. 2. 1.
[solvesql] SQL 문제 풀이 (3) 1. 최고의 근무일을 찾아라 select day, sum(tip) as tip_daily from tips group by day order by tip_daily desc limit 1; 2. 버뮤다 삼각지대에 들어가버린 택배 select date(order_delivered_carrier_date) as delivered_carrier_date, count(*) as orders from olist_orders_dataset where date(order_delivered_carrier_date) between '2017-01-01' and '2017-01-31' and order_delivered_carrier_date is not null and order_delivered_customer_dat.. 2023. 1. 31.
[solvesql] SQL 문제 풀이 (2) 1. 레스토랑 웨이터의 팁 분석 select day, time, round(avg(tip),2) as avg_tip, round(avg(size),2) as avg_size from tips group by day, time; 2. 최근 올림픽이 개최된 도시 select year, upper(substring(city,0,4)) as city from games where year >= 2000 order by year desc; 3.우리 플랫폼에 정착한 판매자 1 select seller_id, count(distinct(order_id)) as orders from olist_order_items_dataset group by seller_id having orders >= 100; 2023. 1. 30.
[solvesql] SQL 문제 풀이 1. 모든 데이터 조회하기 https://solvesql.com/problems/select-all/ select * from points; 2. 일부 데이터 조회하기 https://solvesql.com/problems/select-where/ select * from points where quartet = 'I'; 3. 데이터 정렬하기 https://solvesql.com/problems/order-by/ select * from points where quartet = 'I' order by y; 4. 데이터 그룹으로 묶기 https://solvesql.com/problems/group-by/ select quartet, round(avg(x),2) as x_mean, round(variance(.. 2023. 1. 29.
SQL 예제 group by select payment_method , count(*) from orders where email like '%@naver.com' and course_title = '앱개발 종합반' group by payment_method =>네이버 이메일을 사용하여 앱개발 종합반을 신청한 결제수단별 주문 개수를 구해라. JOIN inner join 은 교집합 left join 은 null 값을 같이 출력 -> 왼쪽값 기준으로 SELECT * from users u left join point_users pu on u.user_id = pu.user_id => users 테이블이 왼쪽(기준) 에다가 point_users를 붙인다. 기준은 u.user_id = pu.user_id select * f.. 2022. 6. 28.
Average Population of Each Continent - BASIC JOIN 제목 그대로 각 지역의 인구 평균을 구하는 문제이다. avg 평균을 이용해야하며, floor를 이용해야 한다 - > 소수점 자리 버림. 또한 group by를 이용해서 그룹을 지어줘야한다 -> 문제 : 모든 대륙의 이름(COUNTRY.Continent)과 각 대륙의 평균 도시 인구(CITY.Population)를 가장 가까운 정수로 내림하여 쿼리합니다. Given the CITY and COUNTRY tables, query the names of all the continents (COUNTRY.Continent) and their respective average city populations (CITY.Population) rounded down to the nearest integer. Note:.. 2022. 6. 9.
African Cities - BASIC JOIN 이전 문제와 푸는 방법은 비슷하다. 혼자 복습할 수 있는 문제였다. 문제를 풀때, 테이블이 어떤 key로 이어져있는지 확인하고 inner join 을 이용해서 country의 continent 값이 africa 인 city 이름을 모두 출력하면 되는 문제였다. Given the CITY and COUNTRY tables, query the names of all cities where the CONTINENT is 'Africa'. Note: CITY.CountryCode and COUNTRY.Code are matching key columns. Input Format The CITY and COUNTRY tables are described as follows: 정답 : select city.name.. 2022. 6. 9.
Population Census - BASIC JOIN SQL join 문을 문제를 풀면서 연습하고 싶어서 join 문제를 풀어보았다. city 테이블과 country 테이블이 2개 존재하며, continent 가 asia 인 인구수를 구하는 문제이다. join할 수 있는 key는 city 테이블의 countrycode 와 country 의 code 이다. Given the CITY and COUNTRY tables, query the sum of the populations of all cities where the CONTINENT is 'Asia'. Note: CITY.CountryCode and COUNTRY.Code are matching key columns. Input Format The CITY and COUNTRY tables are desc.. 2022. 6. 9.