沃梦达 / 编程问答 / php问题 / 正文

如何在数据表的 ssp.class.php 中使用 group by 子句

how to use group by clause in ssp.class.php of datatables(如何在数据表的 ssp.class.php 中使用 group by 子句)

本文介绍了如何在数据表的 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 不支持 JOINGROUP 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 支持 JOINGROUP 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.

这篇关于如何在数据表的 ssp.class.php 中使用 group by 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在数据表的 ssp.class.php 中使用 group by 子句

基础教程推荐