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
program2
tp3
Генерация чисел в диапазоне в MS SQL
BRYAN_BD
tables
Self join producing wrong results -SQL
shrink logs
MS SQL Joins
Test1
FIGURA5.4