Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
sum vs count with multiple options in group by clause
CREATE TABLE sample ( id int,Role CHAR(2), is_active CHAR(1), is_deleted CHAR(1) ); insert into sample values(100,'SM','y','n'),(101,'SM','n','y'), (102,'SM','y','n'),(103,'BC','n','y'),(104,'BC','y','n'),(105,'BC','y','n'), (103,'AI','n','y'),(104,'AI','y','n'),(105,'AI','y','n'); select * from sample; select Role, count(Role) as Total, sum(case when is_active='y' then 1 else 0 end) as Active, sum(case when is_deleted='y' then 1 else 0 end) as Deleted from sample group by Role select Role, count(Role) as Total, count(case when is_active='y' then 1 else 0 end) as Active, count(case when is_deleted='y' then 1 else 0 end) as Deleted from sample group by Role
run
|
edit
|
history
|
help
0
Mc170404738
Rno 37 boat
Query through an error in Sql Server 2008 r2
nnnnn
Student.sql
12
Practice
testing-2
NOT NULL field from SELECT INTO
ex2