dongyan4157 2017-01-23 18:30
浏览 13
已采纳

根据id使用PHP和MySQL计数传递,失败,跳过数字

I have four tables look like below:

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 (referenced with test_case_id in test_case table and test_suite_id with 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_run (referenced with test_suite_id in test_suite table)

id        test_suite_id       name
 1            3               BBH
 2            4               CXN

Now i want to run a where query from test_suite_run by id (for example id=2 in test_suite_run) and want a output look like below:

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

I am new in PHP and MySQL.

  • 写回答

1条回答 默认 最新

  • dpj997991 2017-01-23 19:08
    关注

    Try this:

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码