let's say mysql is something like this
select x,y
from xx
group by y
i want to know how many rows that select will get, i tried to use count but it will n't return all results since i'm using group by.
how to do that?
Thanks
In MySQL, the COUNT() function calculates the number of results from a table when executing a SELECT statement. It does not contain NULL values. The function returns a BIGINT value. It can count all the matched rows or only rows that match the specified conditions.
The GROUP BY statement is often used with aggregate functions ( COUNT() , MAX() , MIN() , SUM() , AVG() ) to group the result-set by one or more columns.
The following are the syntax to get the row count of a single table in MySQL: SELECT COUNT (*) FROM table_name.
SQL – count() with Group By clause The count() function is an aggregate function use to find the count of the rows that satisfy the fixed conditions. The count() function with the GROUP BY clause is used to count the data which were grouped on a particular attribute of the table.
You can wrap your query like so:
SELECT COUNT(*) FROM
(select x,y
from xx
group by y) sub;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With