advanced
Complex Time-Series Analysis
Calculate moving averages and row rankings without self-joins.
📝 Содержимое промпта
Given a table of stock prices with columns 'stock_id', 'timestamp', and 'price', write a single SQL query that calculates the 7-day moving average price for each stock and ranks the stocks by their closing price within a rolling 30-day window. Use window functions to avoid using subqueries or self-joins.