0

需要帮助来修复错误,尝试运行查询并收到错误每个派生表都必须有自己的别名,下面是代码:

$sql="SELECT trouble_type_priority, category_1, category_2, status, COUNT(*) FROM
( SELECT DISTINCT trouble_type_priority, category_1, category_2 FROM tbl_main )
GROUP BY trouble_type_priority,category_1,category_2 HAVING COUNT(*) > 1";
4

2 回答 2

3

您需要给您的子查询一个“别名”或名称。

注意在a子查询之后添加:

$sql="SELECT trouble_type_priority, category_1, category_2, status, COUNT(*) FROM
( SELECT DISTINCT trouble_type_priority, category_1, category_2 FROM tbl_main ) a
GROUP BY trouble_type_priority,category_1,category_2 HAVING COUNT(*) > 1";
于 2013-05-04T12:01:02.577 回答
2

您需要为子查询添加别名:

 $sql="SELECT trouble_type_priority, category_1, category_2, status, COUNT(*)
       FROM
         (SELECT DISTINCT trouble_type_priority, category_1, category_2
          FROM tbl_main) s
       GROUP BY trouble_type_priority, category_1, category_2
       HAVING COUNT(*) > 1";

请注意在 SELECT ... FROM (....) s 之后添加的 's'

于 2013-05-04T12:01:00.047 回答