By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table tbl1(
[groups] nvarchar(50),
[Total # Records] float);
insert into tbl1([groups], [total # records]) values
('Central Business',20),
('Central Business',31),
('Central Business',326),
('Central Business',259),
('Central Business',390),
('Venture Capital',311),
('Venture Capital',236),
('Venture Capital',185),
('Venture Capital',27),
('Venture Capital',611)
create table tbl2(
[groups] nvarchar(50),
[No Action Over 60 Days] float);
insert into tbl2([groups], [No Action Over 60 Days]) values
('Central Business' , 365 ),
('Central Business' , 704 ),
('Central Business' , 428 ),
('Central Business' , 345 ),
('Central Business' , 81 ),
('Venture Capital' , 521 ),
('Venture Capital' , 308 ),
('Venture Capital' , 607 ),
('Venture Capital' , 115 ),
('Venture Capital' , 906 );
20 rows affected
;with table1CTE
as
(
select
[Groups],
sum([total # records]) as [total # records]
from
tbl1
where
[Groups]
in
(
select
[groups]
from
(
select
[groups],
[total # records]
from
tbl1
) as sourceTbl1
pivot
(sum ([total # records])
for [groups]
in
([Central Business],
[Venture Capital])
) as pvt
)
group by [groups]
),--table1CTE
table2CTE as
(
select
[Groups],
groups | total # records | No Action Over 60 Days |
---|---|---|
Central Business | 1026 | 1923 |
Venture Capital | 1370 | 2457 |