how to use group by clause in ssp.class.php of datatables(如何在数据表的 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.
这篇关于如何在数据表的 ssp.class.php 中使用 group by 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在数据表的 ssp.class.php 中使用 group by 子句
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
