SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE Employees ( EMP_ID INT PRIMARY KEY, Name VARCHAR(50), Age INT ); CREATE TABLE Sales ( ID INT PRIMARY KEY, EMP_ID INT, Dept INT, Sales DECIMAL(10, 2), FOREIGN KEY (EMP_ID) REFERENCES Employees(EMP_ID) ); INSERT INTO Employees (EMP_ID, Name, Age) VALUES (1, 'El', 30), (2, 'E2', 40), (3, 'E3', 35), (4, 'E4', 45); INSERT INTO Sales (ID, EMP_ID, Dept, Sales) VALUES (1, 1, 100, 2.0), (2, 2, 200, 3.0), (3, 3, 300, 4.0), (4, 4, 300, 5.0), (5, 1, 100, 6.0); select * from Employees; Select * from Sales; select sum(sl. sales) sum(sl. sales) max(sl.sales) over(partition by sl.dept) as over()' over(partition by sl.dept) as each_dept_sales, max_in_dept from sales) select c. * , e. * from c join emp e on c.emp_id = e. id where c.sales = c.max_in_dept ;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear