How could I obtain a count from multiple colums?

I have a table in SQL server with data of Courses, WorkingArea and Province and I want to get the count of WorkingArea for each Province and for each course.

enter image description here

Could you help me please?

For example, there are 2 "Desempleados" in "Almeria" for "Course A", so I want "2" as result in another column, but when I try to group by, the results are never ok…

The result should be:

CourseName WorkingArea Province Count
COURSE A Desempleado Almería 2
COURSE A Administración Autonómica Almería 1

>Solution :

You use a GROUP BY clause. The GROUP BY clause is used within a SELECT statement to group rows into sets based on the values of one or more columns. It is often used with aggregate functions such as SUM, AVG, MAX, MIN, and COUNT to calculate summary information for each group. e.g.

    , workingarea
    , province
    , count(*) AS cnt
FROM your_table
    , workingarea
    , province

Leave a Reply