Table 使用其他 table 测量
Table measuring using other table
我在数据库中有两个 table。 table 有一个 ID 列。一个 table 始终准确(Table 始终),另一个 table 有时准确(Table 有时)。 Table 有时可能会有多个 ID 映射到 Table Always 上的单个 ID。理想情况下,我希望在两个 table 之间有一个 1-1 映射,但事实并非如此。我如何根据成功映射 (1 - 1) 到 Table Always
来衡量 Table Sometimes hit/accuracy
您可以使用 SQL 查询生成准确度的 id-per-id 报告:
select a.id, coalesce(s.cnt, 0) no_matches
from always a
left join (select id, count(*) cnt from sometimes group by id) s
on s.id = a.id
对于 table always
中的每一行,这会检查有多少行在 sometimes
中匹配。 1
以外的任何值都表示存在映射问题(根本没有匹配项,或者有多个匹配项)。
您可以生成摘要报告。假设您想要 a
中具有正确 1-1 匹配的行的百分比 b:
select avg(case when s.cnt = 1 then 1.0 else 0 end) accuracy_ratio
from always a
left join (select id, count(*) cnt from sometimes group by id) s
on s.id = a.id
也许您想生成三个比率:
select
avg(case when s.cnt = 1 then 1.0 else 0 end) accuracy_ratio,
avg(case when s.cnt is null then 1.0 else 0 end) unmatched_ratio,
avg(case when s.cnt > 1 then 1.0 else 0 end) many_matches_ratio,
from always a
left join (select id, count(*) cnt from sometimes group by id) s
on s.id = a.id
我在数据库中有两个 table。 table 有一个 ID 列。一个 table 始终准确(Table 始终),另一个 table 有时准确(Table 有时)。 Table 有时可能会有多个 ID 映射到 Table Always 上的单个 ID。理想情况下,我希望在两个 table 之间有一个 1-1 映射,但事实并非如此。我如何根据成功映射 (1 - 1) 到 Table Always
来衡量 Table Sometimes hit/accuracy您可以使用 SQL 查询生成准确度的 id-per-id 报告:
select a.id, coalesce(s.cnt, 0) no_matches
from always a
left join (select id, count(*) cnt from sometimes group by id) s
on s.id = a.id
对于 table always
中的每一行,这会检查有多少行在 sometimes
中匹配。 1
以外的任何值都表示存在映射问题(根本没有匹配项,或者有多个匹配项)。
您可以生成摘要报告。假设您想要 a
中具有正确 1-1 匹配的行的百分比 b:
select avg(case when s.cnt = 1 then 1.0 else 0 end) accuracy_ratio
from always a
left join (select id, count(*) cnt from sometimes group by id) s
on s.id = a.id
也许您想生成三个比率:
select
avg(case when s.cnt = 1 then 1.0 else 0 end) accuracy_ratio,
avg(case when s.cnt is null then 1.0 else 0 end) unmatched_ratio,
avg(case when s.cnt > 1 then 1.0 else 0 end) many_matches_ratio,
from always a
left join (select id, count(*) cnt from sometimes group by id) s
on s.id = a.id