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
drop table students; create table students ( id int primary key, student_name varchar(50) not null ); insert into students values (1, 'James'), (2, 'Michael'), (3, 'George'), (4, 'Stewart'), (5, 'Robin'); select id,student_name, case when id%2 <> 0 then lead(student_name,1,student_name) over(order by id) when id%2 = 0 then lag(student_name) over(order by id) end as new_student_name from students;

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

Copy Clear