WITH ref_amt AS ( SELECT dt, user_id, SUM(order_amt) AS order_amt_sum FROM temp1 GROUP BY dt, user_id ) SELECT dt, user_id, order_amt_sum, DENSE_RANK() OVER(PARTITION BY dt ORDER BY order_amt_sum DESC) AS drank FROM ref_amt WHERE drank <= 3;
WITH ref_amt AS ( SELECT user_id, dt, SUM(order_amt) AS order_amt_sum FROM temp2 GROUP BY user_id, dt ), ref_min_date AS ( SELECT user_id, MIN(dt) AS dt_min FROM ref_amt GROUP BY user_id ), cmb_date AS ( SELECT ref_amt.user_id, ref_amt.dt, ref_min_date.dt_min, ref_amt.order_amt_sum, DATEDIFF(ref_amt.dt, ref_min_date.dt_min) AS dt_diff FROM ref_amt LEFT JOIN ref_min_date ON ref_amt.user_id = ref_min_date.user_id ) SELECT DISTINCT user_id FROM cmb_date GROUP BY user_id, dt_diff HAVING COUNT(1) >= 3;
class Solution: def maxVal(self, Vmax: int, Mmax: int, items: pd.DataFrame) -> int: max_val = 0 num_items = [0] * len(items.index) num_items[0] = min(items.iloc[0, 2], Vmax // items.iloc[0, 0], Mmax // items.iloc[0, 1]) max_val = num_items[0] * items.iloc[0, 3] for idx in range(1, len(items.index)): V = items.iloc[idx, 0] M = items.iloc[idx, 1] S = items.iloc[idx, 2] P = items.iloc[idx, 3] V_lft = Vmax - sum(x * y for x, y in zip(num_items, items['V'])) M_lft = Mmax - sum(x * y for x, y in zip(num_items, items['M'])) num_items[idx] = min(S, V_lft // V, M_lft // M) if sum(x * y for x, y in zip(num_items, items['P'])) > max_val: max_val = sum(x * y for x, y in zip(num_items, items['P'])) return max_val
#软件开发笔面经#