Write a query to fetch the number of students from Delhi
Description: Count the students who live in Delhi.
Tables: the exercises use the students (id, name, city, marks, course_id) and courses (id, course_name) tables, with the data from our MySQL INSERT chapter. The students are: Robin (Delhi, 85), Maria (Mumbai, 92), John (Pune, 78), Asha (Jaipur, 88), Vikram (Delhi, 65), Neha (Mumbai, 45).
Hint:
- Use
COUNT(*)withWHERE city = 'Delhi'.
MySQL query to count the students of Delhi
SELECT COUNT(*) AS students_from_delhi
FROM students
WHERE city = 'Delhi';
Output:
Tutorials Class - Output Window
| students_from_delhi |
|---|
| 2 |
How it works
WHEREkeeps only the Delhi rows: Robin and Vikram.COUNT(*)counts them.
Read Aggregate Functions.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |