【问题标题】:Count number of times value appears in column in MySQL计数值出现在 MySQL 中的列中的次数
【发布时间】:2014-09-20 11:01:14
【问题描述】:

尝试到处寻找这个,但我的搜索没有给我任何答案。 希望计算“郊区”列中出现“悉尼”一词的次数

CustomerId  FirstName   LastName    StreetAddress   Suburb  PostCode
C001    James           Smith       400 Kent St     Sydney      2000
C002    Maria           Carpenter   333 Smith St    Westmead    2145
C003    Dennis          Miller      214 Uni Rd      Sydney      2000

我希望它提供如下结果:

numCustomersFromSydney
                    2

【问题讨论】:

  • select count(*) from urtable where urban='Sydney';
  • 或者如果你想要子字符串然后where suburb LIKE '%Sydney%,这是一个相当简单的查询,你可以通过谷歌搜索轻松获得。
  • 无处不在?真的吗?不相信;

标签: mysql sql ms-access count


【解决方案1】:

使用这个简单的查询:

select count(*) as numCustomersFromSydney from table where Suburb = "Sydney";

【讨论】:

    【解决方案2】:

    使用 COUNT() 和别名:

    SELECT
        COUNT(Suburb) AS numCustomersFromSydney
    FROM
        yourtable
    WHERE
        Suburb = 'Sydney'
    

    【讨论】:

      猜你喜欢
      • 2012-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多