I don’t know what you are trying to do, but using the above solutions you use a subquery in the alias table, which is inefficient.
SELECT foo FROM (SELECT COUNT(*) AS foo FROM employees) AS T;
Basically, T is your alias table, and it returns the count column foo, which is a separate record, and it makes no sense to use the SUM (foo) function on it, since it is a single record.
Anyway, the simple answer is:
SELECT Count(1) AS foo from employees;
Since the COUNT function will return the same results no matter which NOT NULL fields you include as parameters for the COUNT function (that is: in parentheses), you can use COUNT (1) to improve performance. Now the database engine will not need to retrieve any data fields; instead, it will just get an integer value of 1.
source share