By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE DataA (
`key1` INTEGER,
`key2` VARCHAR(1)
);
INSERT INTO DataA
(`key1`, `key2`)
VALUES
('1', 'a'),
('2', 'a'),
('2', 'b'),
('3', 'c');
CREATE TABLE DataB (
`key1` INTEGER,
`key2` VARCHAR(1)
);
INSERT INTO DataB
(`key1`, `key2`)
VALUES
('1', 'a'),
('2', 'a'),
('2', 'b'),
('2', 'd'),
('2', 'b'),
('2', 'd');
select avg(case when a.key1 is null then 1.0 else 0 end) output
from (select distinct * from DataB) b left join DataA a
on a.key1 = b.key1 and a.key2 = b.key2
output |
---|
0.25000 |