mysql_num_row with Inner Join

Asked

Viewed 60 times

1

I have 2 tables:

  1. Leads
  2. Shops

The relationship is as follows: 1 store -> N leads

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

I need to list the number of registered leads for each store and then sort in descending order to know which store has the most leads

The Inner Join I’m using duplicates the stores when running the query. HELP

2 answers

2

would be something like this?


SELECT COUNT(le.id) AS total_leads FROM leads AS le
INNER JOIN lojas AS lo ON le.id_loja = lo.id
GROUP BY lo.id
ORDER BY lo.id DESC

  • Dude, perfect!!!!! Got back to me straight! Just that NOME_LOJA did not appear in the final result. How to add this?

  • tries to put something like: SELECT COUNT(le.id) AS total_leads, store name.... See if it works.

  • Incidentally, in case, do you want the name of the store and the total of stores? Explain to me right this part.

1


I would do so:

SELECT nome_loja, uf, (SELECT COUNT(*) FROM leads 
                               WHERE loja_selecionada = nome_loja) AS 'total'
FROM lojas ORDER BY total DESC

Also of course. =)

See working

  • 1

    ANIMAL! Congratulations, it was just that! Thank you!

  • 1

    I just made a change from order by to total and show!! Tks Brow

  • @Léokovaski... XD ... Quiet!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.