Untitled

mail@pastecode.io avatar
unknown
mysql
2 years ago
1.1 kB
1
Indexable
Never
use test;

CREATE TABLE employees (
id integer NOT NULL default '0',
name varchar(255) NOT NULL default '',
since_date date NOT NULL,
PRIMARY KEY (id)
);

INSERT INTO employees (id, name, since_date)
VALUES                       (1, 'Vasya1', '2022-01-01'),
                             (2, 'Vasya2', '2022-01-02'),
                             (3, 'Vasya3', '2022-01-03'),
                             (4, 'Vasya4', '2022-01-04'),
                             (5, 'Vasya5', '2022-01-05'),
                             (6, 'Vasya6', '2022-01-06'),
                             (7, 'Vasya7', '2022-01-07'),
                             (8, 'Vasya8', '2022-01-08'),
                             (9, 'Vasya9', '2022-01-09'),
                             (10, 'Vasya10', '2022-01-10');

DROP PROCEDURE if exists find_employees;
CREATE PROCEDURE find_employees(id INTEGER)
BEGIN
    SELECT e.id, e.name, e.since_date
    FROM employees AS e
    WHERE e.since_date > (SELECT since_date FROM employees WHERE employees.id = id);
END;

call find_employees(3);