How to select a larger number of records based on another SQL table

Asked

Viewed 223 times

1

I have an IMMOBILE table

ID   |   Tipo   | endereço
1    |  Casa    | Rua teste
2    |  Casa    | Rua teste
3    |  Apartamento    | Rua teste

And a sales chart

id | ID_do imovel
1  | 1
2  | 2

I need to know based on the sales chart, which was the type of immovable best selling of the IMMOVEL table. Can anyone help me?

1 answer

1


SELECT 
    i.Tipo AS Tipo,
    COUNT (i.Tipo) AS Quantidade
FROM
    IMOVEIS i INNER JOIN Vendas v ON i.ID = v.ID_do_Imovel
GROUP BY
    i.Tipo
  • 1

    God right, but he returned me all kinds and I wanted only the best seller, for that I put ORDER BY total DESC limit 1

Browser other questions tagged

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