SQL server统计其他行数
我怎么会有这样的结果? 在我看来,我可以查询=>SQL server统计其他行数,sql,sql-server,Sql,Sql Server,我怎么会有这样的结果? 在我看来,我可以查询=> select id, count(no1, no2, no3) where no1='B',no2='B',no3='B' 非常感谢。使用案例陈述 select id, case when no1='B' then 1 else 0 END + case when no2='B' then 1 else 0 END + case when no3='B' then 1 else 0 END As
select id, count(no1, no2, no3) where no1='B',no2='B',no3='B'
非常感谢。使用
案例陈述
select id,
case when no1='B' then 1 else 0 END +
case when no2='B' then 1 else 0 END +
case when no3='B' then 1 else 0 END As Count_All
From yourtable
使用
案例陈述
select id,
case when no1='B' then 1 else 0 END +
case when no2='B' then 1 else 0 END +
case when no3='B' then 1 else 0 END As Count_All
From yourtable
当语句与计数聚合时,使用大小写。最后,用
id
将他们分组:
Select id,
count(case when no1='B' then 1 END) +
count(case when no2='B' then 1 END) +
count(case when no3='B' then 1 END) AS count_all
From yourtable
Group by id
当语句与计数聚合时,使用大小写。最后,用
id
将他们分组:
Select id,
count(case when no1='B' then 1 END) +
count(case when no2='B' then 1 END) +
count(case when no3='B' then 1 END) AS count_all
From yourtable
Group by id
不需要
Count
和Group by
这是不必要的开销Count
和Group by
这是不必要的开销