clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2591627 fiddles created (45703 in the last week).

create table vDemo ( TenNV varchar(50) not null ,MaLC char(1) not null ,NgayLC tinyint not null ) insert into vDemo(tenNV,MaLC,NgayLC) values('Cam' ,'x' ,1) ,('Cam' ,'x' ,2) ,('Cam' ,'x' ,3) ,('Cam' ,'x' ,4) ,('Cam' ,'x' ,5) ,('Ngo' ,'x' ,1) ,('Ngo' ,'x' ,2) ,('Ngo' ,'x' ,3) ,('Ngo' ,'x' ,4) ,('Ngo' ,'x' ,5) ,('Ngo' ,'x' ,6) ,('Ngo' ,'x' ,7) ,('Ngo' ,'x' ,8) ,('Ngo' ,'x' ,9) ,('Ngo' ,'x' ,10) ,('Ngo' ,'x' ,11) ,('Ngo' ,'x' ,12) ,('Ngo' ,'x' ,13) ,('Ngo' ,'x' ,14) ,('Ngo' ,'x' ,15) ,('Ngo' ,'x' ,16) ,('Ngo' ,'x' ,17) select TenNV ,SUM(count_x) as count_x ,SUM(count_L) as count_l from ( select TenNV ,Case when MaLC = 'x' then 1 else 0 end as count_x ,Case when MaLC = 'L' then 1 else 0 end as count_L from vDemo ) A group by TenNV select TenNV ,COUNT(count_x) as count_x ,COUNT(count_L) as count_l from ( select TenNV ,Case when MaLC = 'x' then MaLC else NULL end as count_x ,Case when MaLC = 'L' then MaLC else NULL end as count_L from vDemo ) A group by TenNV
TenNV count_x count_l
Cam 5 0
Ngo 17 0
TenNV count_x count_l
Cam 5 0
Ngo 17 0
Warning: Null value is eliminated by an aggregate or other SET operation.
 hidden batch(es)