限制mysql中特定列中的重复行
我有这样一个问题:限制mysql中特定列中的重复行,mysql,Mysql,我有这样一个问题: select testset, count(distinct results.TestCase) as runs, Sum(case when Verdict = "PASS" then 1 else 0 end) as pass, Sum(case when Verdict <> "PASS" then 1 else 0 end) as fails, Sum(case when latest_issue <> "NULL" then 1 else 0
select testset,
count(distinct results.TestCase) as runs,
Sum(case when Verdict = "PASS" then 1 else 0 end) as pass,
Sum(case when Verdict <> "PASS" then 1 else 0 end) as fails,
Sum(case when latest_issue <> "NULL" then 1 else 0 end) as issues,
Sum(case when latest_issue <> "NULL" and issue_type = "TC" then 1 else 0 end) as TC_issues
from results
join testcases on results.TestCase = testcases.TestCase
where platform = "T1_PLATFORM" AND testcases.CaseType = "M2"
and testcases.dummy <> "flag_1"
group by testset
order by results.TestCase
我的问题是,这是一个结果表,其中包含多次运行的测试用例。所以
我可以使用不同的测试用例来限制运行,但是当我想要通过并且失败时,因为我使用的是用例,所以我无法消除重复
有什么方法可以实现我想要的吗
需要帮忙吗
谢谢
更新:
TestCases Table :
ID TestCase CaseType dummy
1 101 M1 flag_0
2 102 M2 flag_1
Results table :
ID TestCase TestSet Verdict latest_issue Platform
1 101 T1 PASS NONE T1_PLATFORM
2 102 T2 FAIL YES T2_PLATFORM
3 101 T1 FAIL YES T1_PLATFORM
我相信你在追求这样的东西:
select
testset,
count(*) as runs,
sum(passed) as pass,
count(*) - sum(passed) as fails,
sum(issues) as issues,
sum(tc_issues) as tc_issues
from
( select
r.testset,
r.testcase,
max(if(r.verdict = 'PASS', 1, 0)) as passed
max(if(r.latest_issue <> 'NULL', 1, 0)) as issues,
max(if(r.latest_issue <> 'NULL' and issue_type = 'TC', 1, 0)) as tc_issues,
from results r
inner join testcases t on (r.testcase = t.testcase)
where
r.platform = 'T1_PLATFORM'
and t.casetype = 'M2'
and t.dummy <> 'flag_1'
group by
r.testset,
r.testcase
) as t
group by
testset
order by 1
注意:我使用了mysql函数,因为它比case语法更简洁。如果你喜欢相反的方式,它应该仍然有效。如果一个测试用例有一个通过记录和一个失败记录,你想计算哪一个?还是每个人都要1分?请提供一个数据样本和期望的输出。如果一个TestCase2都通过和失败,我想把TestCask当作PASS,不管TestCases有多少个条目,如FAILCan,您可以为结果和测试用例提供表描述。目前尚不清楚哪些数据来自何处。
select
testset,
count(*) as runs,
sum(passed) as pass,
count(*) - sum(passed) as fails,
sum(issues) as issues,
sum(tc_issues) as tc_issues
from
( select
r.testset,
r.testcase,
max(if(r.verdict = 'PASS', 1, 0)) as passed
max(if(r.latest_issue <> 'NULL', 1, 0)) as issues,
max(if(r.latest_issue <> 'NULL' and issue_type = 'TC', 1, 0)) as tc_issues,
from results r
inner join testcases t on (r.testcase = t.testcase)
where
r.platform = 'T1_PLATFORM'
and t.casetype = 'M2'
and t.dummy <> 'flag_1'
group by
r.testset,
r.testcase
) as t
group by
testset
order by 1
select
testset,
count(*) as runs,
count(passed) as pass,
count(*) - count(passed) as fails,
count(issues) as issues,
count(tc_issues) as tc_issues
from
( select
r.testset,
r.testcase,
max(if(r.verdict = 'PASS', 1, NULL)) as passed
max(if(r.latest_issue <> 'NULL', 1, NULL)) as issues,
max(if(r.latest_issue <> 'NULL' and issue_type = 'TC', 1, NULL)) as tc_issues,
from results r
inner join testcases t on (r.testcase = t.testcase)
where
r.platform = 'T1_PLATFORM'
and t.casetype = 'M2'
and t.dummy <> 'flag_1'
group by
r.testset,
r.testcase
) as t
group by
testset
order by 1