How to select greater number of records based on another SQL table

1

I have an IMOVEIS table

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

And a sales table

id | ID_do imovel
1  | 1
2  | 2

I need to know based on the sales chart, which was the best-selling type of property in the IMOVEIS table. Can someone help me?

    
asked by anonymous 26.09.2016 / 14:21

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
    
26.09.2016 / 14:30