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
SELECT DISTINCT (SELECT COUNT(字段名) FROM 表 WHERE part_group = 't'), (SELECT COUNT(字段名) FROM 表 WHERE part_group = 's'), (SELECT COUNT(字段名) FROM 表 WHERE part_group = 'h') FROM 表
要这样写: (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
更正: 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老是记错,不好意思。
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
(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
FROM 表
WHERE part_group = 't'),
(SELECT COUNT(字段名)
FROM 表
WHERE part_group = 's'),
(SELECT COUNT(字段名)
FROM 表
WHERE part_group = 'h')
FROM 表
(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
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老是记错,不好意思。
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