A measurement of four branching-fraction ratios for three-body decays of B mesons involving two open-charm hadrons in the final state is presented. Run 1 and Run 2 pp collision data are used, recorded by the LHCb experiment at centre-of-mass energies 7, 8, and 13 TeV and corresponding to an integrated luminosity of 9 fb−1. The measured branching-fraction ratios are B(B+→D∗+D−K+)B(B+→D¯¯¯¯¯0D0K+)=0.517±0.015±0.013±0.011,B(B+→D∗−D+K+)B(B+→D¯¯¯¯¯0D0K+)=0.577±0.016±0.013±0.013,B(B0→D∗−D0K+)B(B0→D−D0K+)=1.754±0.028±0.016±0.035,B(B+→D∗+D−K+)B(B+→D∗−D+K+)=0.907±0.033±0.014, where the first of the uncertainties is statistical, the second systematic, and the third is due to the uncertainties on the D-meson branching fractions. These are the most accurate measurements of these ratios to date.