Reputation: 104
how i can result like this ? in my mind i can query = >
select id, count(no1, no2, no3) where no1='B',no2='B',no3='B'
thank's very much.
Upvotes: 0
Views: 34
Reputation: 2016
Use Case When
statements with Count
aggregate. Lastly, Group them with 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
Upvotes: 1
Reputation: 93694
Use Case Statement
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
Upvotes: 3