2017-01-23 16 views
-1

根據ID跳過數我有四個表看起來象下面:計數通過,失敗,使用PHP和MySQL

test_case(1 = '通',2 = '失敗',3 = '跳過' )

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表test_case_id和test_suite_id與test_suite表)

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_run(在test_suite表test_suite_id參考)

id  test_suite_id  name 
1   3    BBH 
2   4    CXN 

現在我想運行一個其中查詢從test_suite_run通過ID(例如ID = 2在test_suite_run中)並且想要輸出如下所示:

id(test_suite_run) name  test_suite_name pass fail skip 
1     CXN   test_suite_2  2  2  3 

我是PHP和MySQL的新手。

回答

0

試試這個:

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; 
+0

太感謝你了,親愛的。 – user7421798