Home > OS >  I need to get the numbers of Users for each language
I need to get the numbers of Users for each language

Time:07-23

I have a list of languages and I need to show how many users subscribe to each.

I work on my project with Angular 13 and AsP.net Core 6 and SQLServer but there are two blocked ways

  1. Use angular services in NgFor but return infinite loops and crash.

  2. Use .NET to return the list of languages and loop a second query to get count users but not work.

  3. the last is to Create something with SQLSever ( I don't know how )

[Table languages][1]

table users

CodePudding user response:

In your API you will need to return a payload that you can use to show the results you expect. From the API layer, you need to access the database and transform data to the meet the former challenge. The query to obtain the results is rather straightforward.

SELECT 
    L.lang_id,
    L.title,
    L.description,
    L.image,
    COUNT(*) as UserCount
FROM
    Languages L
    INNER JOIN Users U on U._id_lang = L.id_lang
GROUP BY
    L.id_lang 
  • Related