Twitter SQL Interview Question | Three Days Rolling Average | using Window Function & Self Join
ฝัง
- เผยแพร่เมื่อ 17 ก.ย. 2024
- In this video we will solve the DataLemur SQL Medium level interview question asked in Twitter
Company.
SQL Script
CREATE TABLE tweet_data (
user_id INT,
tweet_date DATETIME,
tweet_count INT
);
INSERT INTO tweet_data (user_id, tweet_date, tweet_count)
VALUES
(111, '2022-06-01 00:00:00', 2),
(111, '2022-06-02 00:00:00', 1),
(111, '2022-06-03 00:00:00', 3),
(111, '2022-06-04 00:00:00', 4),
(111, '2022-06-05 00:00:00', 5),
(111, '2022-06-06 00:00:00', 4),
(111, '2022-06-07 00:00:00', 6),
(199, '2022-06-01 00:00:00', 7),
(199, '2022-06-02 00:00:00', 5),
(199, '2022-06-03 00:00:00', 9),
(199, '2022-06-04 00:00:00', 1),
(199, '2022-06-05 00:00:00', 8),
(199, '2022-06-06 00:00:00', 2),
(199, '2022-06-07 00:00:00', 2),
(254, '2022-06-01 00:00:00', 1),
(254, '2022-06-02 00:00:00', 1),
(254, '2022-06-03 00:00:00', 2),
(254, '2022-06-04 00:00:00', 1),
(254, '2022-06-05 00:00:00', 3),
(254, '2022-06-06 00:00:00', 1),
(254, '2022-06-07 00:00:00', 3);
Easy - Level easy questions -
• Easy Level SQL Intervi...
#sqlserver #dataanalytics #dataanalyst
#sqlqueries #data #sqlqueryinterviewquestionsandanswers #faang #twitter #sql
Please like and subscribe for more interesting SQL interview questions and answers.🙏
SELECT user_id,
tweet_date,
ROUND(AVG(tweet_count) OVER(PARTITION BY user_id ORDER BY tweet_date ROWS BETWEEN 2 Preceding AND 0 following),2) as average_3_day_rolling
FROM tweet_data;