You didn't say if this errors out ...
Create table tmp
select w.weekend, d2.code as family, d2.amount
from weekendings w
join dr02 d2 on (w.weekend >= d2.date and d2.t1 <> "g")
or (w.weekend >= d2.weekend and d2.t1 = "g")
where d2.amount is not null;
select weekend, code, sum(amount) as owing
from tmp
group by weekend, code
order by weekend, code
How much RAM?
Set tmp_table_size=15G
These are innodb tables, right?
Set innodb_buffer_pool_size= three quarters of available ram
Current wisdom is to leave multi-core optimisation to MySQL with ...
innodb_thread_concurrency = 0
innodb_read_io_threads = 64
innodb_write_io_threads = 64
Restart the server, While the query is running, run ...
show engine innodb status\G
... and post the result here if the error still occurs.