【问题标题】:Count pass, fail, skip number according to id using PHP and MySQL使用PHP和MySQL根据id计算通过,失败,跳过数字
【发布时间】:2017-06-08 08:48:53
【问题描述】:

我有四个表如下所示:

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 表中用 test_case_id 引用,在 test_suite 表中用 test_suite_id 引用)

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

现在我想通过 idtest_suite_run 运行 where 查询(例如 test_suite_run 中的 id=2)并想要输出外观如下:

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

我是 PHP 和 MySQL 的新手。

【问题讨论】:

    标签: php mysql join count where-clause


    【解决方案1】:

    试试这个:

    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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-28
      • 1970-01-01
      相关资源
      最近更新 更多