问题描述
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?
推荐答案
解决方案
类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数据表:将WHERE,JOIN和GROUP BY与ssp.class.php结合使用以获取更多信息.
See jQuery DataTables: Using WHERE, JOIN and GROUP BY with ssp.class.php for more information.
这篇关于如何在数据表的ssp.class.php中使用group by子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!