有一份数据表,
里面有几十万条数据。每个数据都有一个“所属城市”属性。
所有的数据可能涉及到几十个城市。我现在想知道,这些数据中,
总共涉及到那些城市。这个sql语句该怎么写来着?
谢谢!!

解决方案 »

  1.   

    select 所属城市 from tb_name group by 所属城市;
      

  2.   

    或:select distinct 所属城市 from tb_name;
      

  3.   

    要统计这些城市的个数呢?select count(distinct 所属城市) from tb_name;
      

  4.   

    select count(distinct city) from table;
      

  5.   


    select distinct city from yourTable;
      

  6.   


    select count(distinct city) from yourTable;
      

  7.   

    统计城市:
    select 所属城市 from tb_name group by 所属城市;
    统计城市个数:
    select count(所属城市) from tb_name group by 所属城市;