如何创建数学方程是一个sql调用PHP

如何创建数学方程是一个sql调用PHP,php,Php,我不知道这是否可能。我有一个表格,我想在其中找到Yes出现在recall列中的总次数,然后我想找到这个舞者的总行数。在此之后,我想将Yes出现的次数除以每个dancer\u id的总行数 dancer\u id在一个数组中,因此可能有许多舞者需要这些信息 我就是这样尝试的: //GET OVERALL TOTAL $overall_total = " SELECT * from mark_cards1 where dancer_id1='$champId'

我不知道这是否可能。我有一个表格,我想在其中找到
Yes
出现在
recall
列中的总次数,然后我想找到这个舞者的总行数。在此之后,我想将
Yes
出现的次数除以每个
dancer\u id
的总行数

dancer\u id
在一个数组中,因此可能有许多舞者需要这些信息

我就是这样尝试的:

 //GET OVERALL TOTAL   
                $overall_total = " SELECT * from mark_cards1 where dancer_id1='$champId'";
                $overall_Res = mysqli_query($con,$overall_total);
                $total_MC = mysqli_num_rows($overall_Res);

                //GET RECALL FOR OVERALL PLACEMENT CHART
                $recallsql = "SELECT * from mark_cards1 where dancer_id1='$champId' and was_recalled = 'Yes'";
                $recallRes = mysqli_query($con,$recallsql);
                $total_recall = mysqli_num_rows($recallRes);

                //RECALL COUNT / FEIS COUNT

                $feis_total = $total_MC; 

                $recall_total = $total_recall; 

                $overall_placement = $recall_total / $feis_total;


                echo "
                ['$champName', '$champlvl', '$champGender', '$champTeacher', $champAge, $overall_placement, 5],
                ";

有没有更简单的方法?我能在一次sql调用中获得此信息吗?

请检查您的下面的查询,如果您对此有任何疑问,请告诉我

select 
count(
    case when dancer_id1 = '$champId' then 1 else null end
) as total_MC, 
count(
    case when (
        dancer_id1 = '$champId' 
        and was_recalled  = 'Yes'
    ) then 1 else null end
) as total_recall 
from 
 mark_cards

运行此查询后,您将得到两个与计数相关的变量,并将它们除以,以便获得所需的结果。

您可以使用SQL中的
case
方法。完美,正是我所要的。非常感谢。