代码之家  ›  专栏  ›  技术社区  ›  hummingBird

用嵌套查询替换mysql->php->mysql

  •  1
  • hummingBird  · 技术社区  · 14 年前

    我准备好做以下工作:

    1. 按位置从myTable组中选择位置
    2. 将结果加载到数组(可能有几百个位置)
    3. 选择COUNT(*)作为total,tbl.location作为location FROM(从myTable选择DISTINCT customer FROM myTable WHERE location=location_inserted_by_php)作为tbl;

    现在,这听起来是一个相当愚蠢的解决方案,但我对嵌套查询还不太了解。有什么帮助吗?

    1 回复  |  直到 14 年前
        1
  •  2
  •   Brad Mace Mike King    14 年前
    SELECT location,count(distinct customer) as visitors from customer_locations
    GROUP BY location
    ORDER BY visitors DESC
    LIMIT 10
    

    按唯一访问者数获取前10个位置