By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table table1 (
Personalnr int
);
insert into table1 values (1),(2);
create table table2 (
Personalnr int,
Date date
);
insert into table2 values
(1, '2023-09-1'),
(2, '2023-09-1'),
(2, '2023-09-2');
5 rows affected
select t1.Personalnr,
MAX(case when t2.Date = '2023-09-01' then 1 else 0 end) as [2023-09-01],
MAX(case when t2.Date = '2023-09-02' then 1 else 0 end) as [2023-09-02]
from table1 t1
inner join table2 t2 on t1.Personalnr = t2.Personalnr
group by t1.Personalnr
Personalnr | 2023-09-01 | 2023-09-02 |
---|---|---|
1 | 1 | 0 |
2 | 1 | 1 |