I have a SQL query for which I needed to have result rows count and results as the output of query.
For example,
SELECT count(*) total, id, name, age, grade
FROM Employee
where grade = 10;
It prints only one row with total count. Please let me know what could be missing in query.
With GROUP BY:
Table:
id name age grade
1 ABC 30 10
2 DEF 31 10
3 GHI 29 6
4 PQR 29 10
Query:
SELECT count(*) total, id, name, age, grade
FROM Employee
where grade = 10
group by id, name, age, grade
total id name age grade
1 1 ABC 30 10
1 2 DEF 31 10
1 4 PQR 29 10
Under total, I expect to have 3 as the value although it will be repeated. Here my intention is to have total row count and result rows as part of single query.
Aucun commentaire:
Enregistrer un commentaire