D
D
Danila09876542019-12-19 18:54:27
SQL
Danila0987654, 2019-12-19 18:54:27

How to count the number of students per course?

5dfb9c6af0bf5197965561.png
There is a database of students and groups. Group number example: P3-1; 19IS1-1; P4-2; IF2-1D;
I need one SQL query to count them.
Here are the codes separately, but I don’t know how to combine them into one, but they require me to SELECT COUNT(*) as count1 From Students Where Group_Number Like '%1-%'
SELECT COUNT(*) as count2 From Students Where Group_Number Like ' %2-%'
SELECT COUNT(*) as count3 From Students Where Group_Number Like '%3-%'
SELECT COUNT(*) as count4 From Students Where Group_Number Like '%4-%'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2019-12-19
@Danila0987654

Something like

SELECT COUNT(*) N, SUBSTRING(Номер_группы, PATINDEX('%[12345]%', Номер_группы), 1) Course
FROM Студенты
GROUP BY Course;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question