Reputation: 119
I'm confused with count aggregation function.
Below sentence is mysql and it worked without a groupby clause. how could it be possible?
SELECT
COUNT(1) AS cnt
FROM dual;
result : 1
Is there any parameter that groupby clause is default when count aggregation function called.
help me out plz.
Upvotes: 1
Views: 56
Reputation: 1269643
Aggregation functions such as COUNT()
, SUM()
and AVG()
are used in aggregation queries. Such queries calculate the values based on groups of rows that are summarized into a single row in the result set.
Normally, an aggregation query uses a GROUP BY
to define the rows in the result set. The result set has one row for each unique combination of the GROUP BY
keys found in the data.
When such a query does not have a GROUP BY
, then the entire table is considered a group and it is summarized into exactly one row. Incidentally, this is true even when there are no rows in the table. The result would be a count of 0
.
Upvotes: 7