contributte / datagrid

:muscle: DataGrid for Nette Framework: filtering, sorting, pagination, tree view, table view, translator, etc
https://contributte.org/packages/contributte/datagrid/
MIT License
292 stars 195 forks source link

Incorrect rows count when using GROUP BY with multiple columns - Nette\Database\Table #991

Open matoni555 opened 3 years ago

matoni555 commented 3 years ago

Hi, I found the bug in Nette\Database\Table data source when using GROUP BY with multiple columns.

Here is example of SQL queries. Query for the datagrid with 703 total rows.

SELECT `id`, `title`, `variant`, CONCAT_WS(" - ", `title`, `variant`, `course_city`, `course_date`) AS `full_name` 
FROM `orders_products` 
GROUP BY `title`, `variant`, `course_city`, `course_date`;

Datagrid generated this SQL query from the getCount() function which gets 0 rows.

SELECT COUNT(DISTINCT `title`, `variant`, `course_city`, `course_date`) 
FROM `orders_products`;

I think right SQL query with multiple GROUP BY columns should be:

SELECT COUNT(*) 
FROM (
SELECT COUNT(id) 
FROM `orders_products`
GROUP BY `title`, `variant`, `course_city`, `course_date`
) AS x;

Best regards

radekdostal commented 3 years ago

Maybe related with https://github.com/contributte/datagrid-nette-database-data-source/pull/12.