SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table s ( id int, status text ); insert into s values (1, 'lock'), (2, 'read'), (3, 'write'); create table u ( id int, a int, b int, c int ); insert into u values (1, 1, 1, 2), (2, 3, 2, 1 ); select u.id , min(case when u.a = s.id then s.status end) a_status, min(case when u.b = s.id then s.status end) b_status, min(case when u.c = s.id then s.status end) c_status from u cross join s group by u.id;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear