尝试从查询中生成汇总总计等的表格,但无法使其正常工作。
我有这个代码:
<?php
$assigned = $_POST['Sales_Exec'];
$date = $_POST['DateSelect'];
$Renewed = "SUM(CASE WHEN Outcome = 'Renewed' THEN 1 ELSE 0 END) AS 'Renewed <br/> Cases'";
$Lapsed = "SUM(CASE WHEN Outcome = 'Lapsed' THEN 1 ELSE 0 END) AS 'Lapsed <br/> Cases'";
$Open = "SUM(CASE WHEN Outcome = 'Open' THEN 1 ELSE 0 END) AS 'Outstanding <br/> Cases'";
$Total = "SELECT COUNT(Assigned) as 'Total <br/> Assigned";
echo GenerateTable("SELECT COUNT(Assigned) as 'Total <br/> Assigned, $Open, $Renewed, $Lapsed FROM Data WHERE Assigned = '$assigned' ");
?>
并收到此错误:
MySQL 错误:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册以获取正确的语法,以便在 'Open' THEN 1 ELSE 0 END) AS 'Outstanding Cases', SUM(CASE WHEN Outcome = ' at line 1 附近使用
并且无法发现我哪里出错了。
除此之外,我还需要根据续订案件到分配案件总数的续订“转换”百分比。我试过了
$Conversion = $Renewed/$Total;
但这并没有那么远,可能是因为上面的原始错误。我还需要将其四舍五入到最接近的百分比整数,即(95.67868786% 等于 96%)。
真的不知道如何让这个工作,所以任何帮助将不胜感激,在此先感谢您!