Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
-- Устанавливаем значение переменной @lim SET @lim = (SELECT COUNT(*) FROM rental WHERE customer_id = 1); -- Вычисляем лимит как @lim - 1 и сохраняем в другую переменную SET @limit_value = @lim - 1; -- Выполняем основной запрос с использованием переменной SELECT *, LAG(rental_date) OVER (ORDER BY rental_date) AS pr_rent, LAG(return_date) OVER (ORDER BY rental_date) AS pr_return FROM rental WHERE customer_id = 1 ORDER BY rental_date LIMIT @limit_value OFFSET 5;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear