select count(name) from tablename group by name
得到的是记录集,只一列!
不知道需不需要变成一行?

解决方案 »

  1.   

    select 
    (select count(name) from tablename where name='t'),
    (select count(name) from tablename where name='s'),
    (select count(name) from tablename where name='h'),
    from tablename 
      

  2.   

    SELECT DISTINCT (SELECT COUNT(字段名)
                         FROM 表
                         WHERE part_group = 't'),
              (SELECT COUNT(字段名)
             FROM 表
             WHERE part_group = 's'),
              (SELECT COUNT(字段名)
             FROM 表
             WHERE part_group = 'h')
    FROM 表
      

  3.   

    要这样写:
    (Sybase or MS Sql server)
    select t_count=sum(case name when 't' then 1 else 0 end),
           s_count=sum(case name when 's' then 1 else 0 end),
           h_count=sum(case name when 'h' then 1 else 0 end)
    from table1(Oracle)
    select sum(case name when 't' then 1 else 0 end) as t_count,
           sum(case name when 's' then 1 else 0 end) as s_count,
           sum(case name when 'h' then 1 else 0 end) as h_count
    from table1
      

  4.   

    更正:
    select t_count=sum(case when name='t' then 1 else 0 end),
            s_count=sum(case when name='s' then 1 else 0 end),
            h_count=sum(case when name='h' then 1 else 0 end)
    from table1老是记错,不好意思。
      

  5.   

    for oracle:select sum(decode(column_name,'t',1,0)) as number_of_t,
           sum(decode(column_name,'s',1,0)) as number_of_s,
           sum(decode(column_name,'h',1,0)) as number_of_h
       from table_name