例如,我在MS SQL Server中有一个表:
Feature, Option1, Option2
-------------------------
Agent, Yes, No
Agent, No, No
Console, No, Yes,
Console, Yes, Yes
我需要编写一个返回的查询:
Feature, Option1 Yes Count, Option2 Yes Count
---------------------------------
Agent, 1, 0
Console, 1, 2
我应该使用什么查询?
答案 0 :(得分:1)
select Feature,
count(nullif(Option1,'no')) as 'Option1 Yes Count',
count(nullif(Option2,'no')) as 'Option2 Yes Count'
from table_name
group by feature