Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php DataTables服务器端:使用GROUPBY和SUM进行查询_Php_Jquery Datatables_Server Side - Fatal编程技术网

Php DataTables服务器端:使用GROUPBY和SUM进行查询

Php DataTables服务器端:使用GROUPBY和SUM进行查询,php,jquery-datatables,server-side,Php,Jquery Datatables,Server Side,我正在使用DataTables服务器端显示我的数据。 () () 我能够通过以下方式扩展此工具: echo json_encode( SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $groupby ) ); 在类ssp.class.php中 $data = self::sql_exec( $db, $bindings, "SELECT SQL_CALC_FOUND_ROWS `".implode

我正在使用DataTables服务器端显示我的数据。 () ()

我能够通过以下方式扩展此工具:

echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $groupby )
);
在类ssp.class.php中

$data = self::sql_exec( $db, $bindings,
    "SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", self::pluck($columns, 'db'))."`
     FROM `$table`
     $where
     $groupby
     $order
     $limit"
);
但是当我想要一列的和时,我得到了一个错误,没有找到列和(GrossPrice)

以下是列的处理方式:

$columns = array(
    array( 'db' => 'ProductDescription',  'dt' => 0 ),
    array( 'db' => 'SUM(GrossPrice)',   'dt' => 1 ),
    array( 'db' => 'SUM(Number)',   'dt' => 2 )
);

我找到了一个解决方案:

我用'sum()'-查询在mysql中创建了一个视图,并使用datatables来显示这个视图


希望这能为其他人服务。

老问题,但我为有同样问题的人回答

可以与joinQuery一起使用。我们使用joinQuery,因为如果不使用,SSP类将使用自己的查询

$columns = array(
    array('db' => 'x.ProductDescription', 'dt' => 0, 'field' => 'ProductDescription'),
    array('db' => 'SUM(x.GrossPrice) as GrossPrice', 'dt' => 1, 'field' => 'GrossPrice'),
    array('db' => 'SUM(x.Number) as Number', 'dt' => 2, 'field' => 'Number')
);
joinQuery示例:

$joinQuery = "FROM {$table} AS x";
这样称呼:

echo json_encode(
   SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery)
);
这个类是为连接查询定制的,但您可以这样使用。谢谢你给我上这堂课