Skip to content

Instantly share code, notes, and snippets.

@puneetverma24
Created May 31, 2025 06:54
Show Gist options
  • Select an option

  • Save puneetverma24/ba6eebd9b41ee6fe7361ce8bdbd616c1 to your computer and use it in GitHub Desktop.

Select an option

Save puneetverma24/ba6eebd9b41ee6fe7361ce8bdbd616c1 to your computer and use it in GitHub Desktop.
-- Refer https://www.backendmesh.com/sql-window-functions-a-comprehensive-guide/
-- Database: `window_practice`
--
-- --------------------------------------------------------
--
-- Table structure for table `daily_sales`
--
CREATE TABLE `daily_sales` (
`region` varchar(20) DEFAULT NULL,
`sale_date` date DEFAULT NULL,
`sales_amount` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
--
-- Dumping data for table `daily_sales`
--
INSERT INTO `daily_sales` (`region`, `sale_date`, `sales_amount`) VALUES
('East', '2023-05-01', 100),
('East', '2023-05-02', 120),
('East', '2023-05-03', 90),
('East', '2023-05-04', 130),
('East', '2023-05-05', 110),
('West', '2023-05-01', 90),
('West', '2023-05-02', 130),
('West', '2023-05-03', 115),
('West', '2023-05-04', 140),
('West', '2023-05-05', 120);
-- --------------------------------------------------------
--
-- Table structure for table `employees`
--
CREATE TABLE `employees` (
`employee_id` int(11) NOT NULL,
`first_name` varchar(50) DEFAULT NULL,
`last_name` varchar(50) DEFAULT NULL,
`department_id` int(11) DEFAULT NULL,
`salary` int(11) DEFAULT NULL,
`hire_date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
--
-- Dumping data for table `employees`
--
INSERT INTO `employees` (`employee_id`, `first_name`, `last_name`, `department_id`, `salary`, `hire_date`) VALUES
(1, 'John', 'Doe', 101, 70000, '2018-04-12'),
(2, 'Jane', 'Smith', 101, 85000, '2017-03-09'),
(3, 'Alice', 'Johnson', 102, 60000, '2020-06-01'),
(4, 'Bob', 'Lee', 101, 85000, '2021-11-15'),
(5, 'Charlie', 'Brown', 103, 95000, '2016-07-23'),
(6, 'Eva', 'Green', 102, 67000, '2019-08-11'),
(7, 'David', 'Clark', 103, 95000, '2015-05-30'),
(8, 'Fiona', 'White', 101, 72000, '2020-01-10'),
(9, 'George', 'Black', 102, 60000, '2022-02-22'),
(10, 'Hannah', 'Scott', 103, 90000, '2018-12-03');
-- --------------------------------------------------------
--
-- Table structure for table `employee_salaries`
--
CREATE TABLE `employee_salaries` (
`employee_id` int(11) DEFAULT NULL,
`salary` int(11) DEFAULT NULL,
`effective_date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
--
-- Dumping data for table `employee_salaries`
--
INSERT INTO `employee_salaries` (`employee_id`, `salary`, `effective_date`) VALUES
(1, 60000, '2019-01-01'),
(1, 65000, '2020-01-01'),
(1, 70000, '2021-01-01'),
(2, 80000, '2019-01-01'),
(2, 85000, '2021-01-01'),
(3, 50000, '2020-06-01'),
(3, 55000, '2021-06-01'),
(3, 60000, '2022-06-01');
-- --------------------------------------------------------
--
-- Table structure for table `purchases`
--
CREATE TABLE `purchases` (
`customer_id` int(11) DEFAULT NULL,
`purchase_date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
--
-- Dumping data for table `purchases`
--
INSERT INTO `purchases` (`customer_id`, `purchase_date`) VALUES
(1, '2023-01-05'),
(1, '2023-02-15'),
(1, '2023-03-22'),
(2, '2023-01-10'),
(2, '2023-06-25'),
(3, '2023-03-05');
-- --------------------------------------------------------
--
-- Table structure for table `user_logins`
--
CREATE TABLE `user_logins` (
`user_id` int(11) DEFAULT NULL,
`login_date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
--
-- Dumping data for table `user_logins`
--
INSERT INTO `user_logins` (`user_id`, `login_date`) VALUES
(1, '2024-01-01'),
(1, '2024-01-02'),
(1, '2024-01-04'),
(1, '2024-01-05'),
(1, '2024-01-08');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `employees`
--
ALTER TABLE `employees`
ADD PRIMARY KEY (`employee_id`);
COMMIT;
@puneetverma24

puneetverma24 commented May 31, 2025 •

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment