Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

SELECT
      coursename
    , workingarea
    , province
    , count(*) AS cnt
FROM your_table
GROUP BY
      coursename
    , workingarea
    , province
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading