MS-Access -> SELECT AS + ORDER BY = error

前端 未结 7 2037
我在风中等你
我在风中等你 2020-12-07 01:52

I\'m trying to make a query to retrieve the region which got the most sales for sweet products. \'grupo_produto\' is the product type, and \'regiao\' is the region. So I got

7条回答
  •  眼角桃花
    2020-12-07 02:33

    How about:

    SELECT TOP 1  r.nm_regiao 
    FROM (SELECT Dw_Empresa.cod_regiao, 
                 Count(Dw_Empresa.cod_regiao) AS CountOfcod_regiao
          FROM Dw_Empresa
          WHERE Dw_Empresa.[grupo_produto]='1'
          GROUP BY Dw_Empresa.cod_regiao
          ORDER BY Count(Dw_Empresa.cod_regiao) DESC) d
    INNER JOIN tb_regiao AS r 
    ON d.cod_regiao = r.cod_regiao
    

提交回复
热议问题