使用 PHP 和 MySQL 根据 id 计算通过、失败、跳过数字
Count pass, fail, skip number according to id using PHP and MySQL
我有四个 table 如下所示:
test_case (1='pass',2='fail',3='skip')
id testing_status
1 1
2 3
3 1
4 2
5 3
6 2
7 2
8 3
test_suite_with_case(在 test_case table 和 test_suite_id 中用 test_case_id 引用 test_suite table)
id test_suite_id test_case_id
1 4 1,3,5,2,6,7,8
2 3 2,5,4,6,7
test_suite
id test_suite_name
3 test_1
4 test_2
test_suite_运行(在test_suitetable中用test_suite_id引用)
id test_suite_id name
1 3 BBH
2 4 CXN
现在我想 运行 来自 test_suite_运行 的 where 查询id(例如 test_suite_运行 中的 id=2)并希望输出如下所示:
id(test_suite_run) name test_suite_name pass fail skip
1 CXN test_suite_2 2 2 3
我是 PHP 和 MySQL 的新人。
试试这个:
select
tr.id,
tr.name,
ts.test_suite_name,
sum(testing_status = 1) pass,
sum(testing_status = 2) fail,
sum(testing_status = 3) skip
from test_suite_run tr
inner join test_suite ts on tr.test_suite_id = ts.id
inner join test_suite_with_case tsc on ts.id = tsc.test_suite_id
inner join test_case tc on find_in_set(tc.id, tsc.test_case_id) > 0
group by
tr.id,
tr.name,
ts.test_suite_name;
我有四个 table 如下所示:
test_case (1='pass',2='fail',3='skip')
id testing_status
1 1
2 3
3 1
4 2
5 3
6 2
7 2
8 3
test_suite_with_case(在 test_case table 和 test_suite_id 中用 test_case_id 引用 test_suite table)
id test_suite_id test_case_id
1 4 1,3,5,2,6,7,8
2 3 2,5,4,6,7
test_suite
id test_suite_name
3 test_1
4 test_2
test_suite_运行(在test_suitetable中用test_suite_id引用)
id test_suite_id name
1 3 BBH
2 4 CXN
现在我想 运行 来自 test_suite_运行 的 where 查询id(例如 test_suite_运行 中的 id=2)并希望输出如下所示:
id(test_suite_run) name test_suite_name pass fail skip
1 CXN test_suite_2 2 2 3
我是 PHP 和 MySQL 的新人。
试试这个:
select
tr.id,
tr.name,
ts.test_suite_name,
sum(testing_status = 1) pass,
sum(testing_status = 2) fail,
sum(testing_status = 3) skip
from test_suite_run tr
inner join test_suite ts on tr.test_suite_id = ts.id
inner join test_suite_with_case tsc on ts.id = tsc.test_suite_id
inner join test_case tc on find_in_set(tc.id, tsc.test_case_id) > 0
group by
tr.id,
tr.name,
ts.test_suite_name;