본문 바로가기

전체 글625

leetcode : 1193. Monthly Transactions I leetcode : 1193. Monthly Transactions I[leetcode : 1193. Monthly Transactions I]다이어그램erDiagram TRANSACTIONS { int id PK varchar country enum state int amount date trans_date }문제 풀이MySQL-- Solution 1with tr_all as ( select concat(year(trans_date),'-',lpad(month(trans_date),2,'0')) as month, country, count(*) as trans_count, sum(amount) as tra.. 2025. 1. 17.
leetcode : 1164. Product Price at a Given Date leetcode : 1164. Product Price at a Given Date[leetcode : 1164. Product Price at a Given Date]다이어그램erDiagram Products { int product_id PK int new_price date change_date PK }목표8월 16일의 PRICE 구하기문제 풀이MySQLWITH B16 AS ( SELECT * FROM ( SELECT PRODUCT_ID, NEW_PRICE AS PRICE_A, ROW_NUMBER() OVER (PARTITION BY PRODUCT_ID ORDER BY CHANGE_DATE DESC) AS I.. 2025. 1. 16.
leetcode : 1174. Immediate Food Delivery II leetcode : 1174. Immediate Food Delivery II[leetcode : 1174. Immediate Food Delivery II]다이어그램erDiagram Food_Delivery { int delivery_id PK int customer_id date order_date date customer_pref_delivery_date }목표유저의 첫 주문 중 당일 배송 상품의 비율 구하기문제 풀이첫 주문을 찾기 위해서는 유저별로 주문날짜, 배송날짜의 최소값을 가져온다.그 중에서 주문날짜=배송날짜인 것을 찾는다.전체 주문 수와 주문날짜=배송날짜인 것의 비율을 구한다.MySQL-- Solution 1with temp as.. 2025. 1. 16.
leetcode : 1158. Market Analysis I leetcode : 1158. Market Analysis I[leetcode : 1158. Market Analysis I]다이어그램erDiagram Users { int user_id PK date join_date varchar favorite_brand } Orders { int order_id PK date order_date int item_id FK int buyer_id FK int seller_id FK } Items { int item_id PK varchar item_brand } Orders ||--o{ Users : "b.. 2025. 1. 15.