如何在数据表的 ssp.class.php 中使用 group by 子句
sql 应该是
select max(id),Staff_name from position group by Staff_name
我修改了ssp.class.php
.
SELECT SQL_CALC_FOUND_ROWS ".implode(", ", self::pluck($columns, 'db'))."
FROM $table
$where
$order
$limit group by Staff_name.
然而,它不起作用.这个sql怎么实现?
However, it dose not work. How to realize this sql?
推荐答案
SOLUTION
Class ssp.class.php
不支持 JOIN
、GROUP BY
或子查询,但有一个解决方法.诀窍是在服务器端处理脚本 (server_processing.php
) 中的 $table
定义中使用如下所示的子查询.
SOLUTION
Class ssp.class.php
doesn't support JOIN
, GROUP BY
or sub-queries, but there is a workaround. The trick is to use sub-query as shown below in $table
definition in you server-side processing script (server_processing.php
).
例如:
$table = <<<EOT
(
SELECT
MAX(id),
Staff_name
FROM position
GROUP BY Staff_name
) temp
EOT;
$primaryKey = 'id';
$columns = array(
array( 'db' => 'id', 'dt' => 0 ),
array( 'db' => 'Staff_name', 'dt' => 1 )
);
$sql_details = array(
'user' => '',
'pass' => '',
'db' => '',
'host' => ''
);
require( 'ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
您还需要编辑 ssp.class.php
并将 FROM `$table`
的所有实例替换为 FROM $table
以删除反引号.
You also need to edit ssp.class.php
and replace all instances of FROM `$table`
with FROM $table
to remove backticks.
还有 github.com/emran/ssp 存储库,其中包含增强的 ssp.class.php
支持 JOIN
和 GROUP BY
.
There is also github.com/emran/ssp repository that contains enhanced ssp.class.php
supporting JOIN
and GROUP BY
.
参见 jQuery DataTables:使用 WHERE、JOIN 和 GROUP BY 与 ssp.class.php 了解更多信息.
See jQuery DataTables: Using WHERE, JOIN and GROUP BY with ssp.class.php for more information.
相关文章