본문 바로가기

Algorithm & SQL179

[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.
최대공약수(gcd) , 최소공배수(lcm) https://school.programmers.co.kr/learn/courses/30/lessons/12953 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 위의 문제 풀이를 위해 최대공약수와 최소공배수의 로직을 작성 static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static int lcm(int a, int b) { return a*b / gcd(a,b); } 2022. 12. 27.
백준 JAVA 1012 유기농 배추 https://www.acmicpc.net/problem/1012 1012번: 유기농 배추 차세대 영농인 한나는 강원도 고랭지에서 유기농 배추를 재배하기로 하였다. 농약을 쓰지 않고 배추를 재배하려면 배추를 해충으로부터 보호하는 것이 중요하기 때문에, 한나는 해충 방지에 www.acmicpc.net 한 달만에 다시 dfs 를 풀어봤는데 기억이 잘 안나서 접근 방법을 보고 같은 코드가 아닌 다른 코드로 생각해서 풀었다. 시간이 40ms 정도 줄었는데, 아예 처음 접했을 때보다는 조금 구현이 수월해진 것 같다. 원래 visited 배열을 사용해서 풀었는데, 이번엔 없이 풀을 수 있을 것 같아 만들지 않고 풀었다. 단순히 0 , 1 만을 비교하는 것으로 구현했다. static void dfs(int x, in.. 2022. 9. 10.
백준 JAVA 1629 곱셈 https://www.acmicpc.net/problem/1629 1629번: 곱셈 첫째 줄에 A, B, C가 빈 칸을 사이에 두고 순서대로 주어진다. A, B, C는 모두 2,147,483,647 이하의 자연수이다. www.acmicpc.net 거의 한시간 반동안 잡고있었는데, 못풀어서 다른 블로그의 도움을 받았다. 모듈러 연산과 재귀를 이용해야 하는문제였고, 코드만 보니 이해가 안가서 몇개의 예제를 만들어서 하나하나 분석하니 이해가 됐다. 3~4일 정도 지나고 다시 트라이 해봐야겠다. 가장 중요한 로직이다. cal 메서드를 만들었는데, 결론은 모듈러 연산을 이용한 코드이다. b 만큼 제곱해야하므로, 2로 b == 0 or b== 1 때까지 나누어야 한다. 또한, b가 짝수일때, 홀수일때를 나누어야 한.. 2022. 9. 9.
백준 JAVA 3986 좋은 단어 스택을 활용해서 풀어야하는 문제이다. for (int j = 0; j < str.length(); j++) { if (st.isEmpty() || (st.peek() != str.charAt(j))) { st.push(str.charAt(j)); } else { st.pop(); } } 알파벳을 넣을때의 조건이다. 처음에는 스택이 아예 비어있으니, peek을 사용할 수 없다. 따라서 isEmpty() 를 추가해서 비교 후 추가할 수 있게 작성했다. push 할 조건이 아니라면 ( peek했는데 삽입할 알파벳과 같다면 ) pop 으로 꺼내준다 if (st.isEmpty()) { count++; } 비어있으면 조건에 만족하기 때문에, count 를 추가시켜준다 package BAEKJOON.Silver.Ⅳ;.. 2022. 9. 9.