clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
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. 984328 fiddles created (11678 in the last week).

CREATE TABLE TableX ([col_A] varchar(20),[col_B] float);
 hidden batch(es)


INSERT INTO TableX(col_A,col_B) VALUES ('b123',10), ('b124',20), ('b123',30), ('b124',40), ('b123',50), ('a123',1), ('a124',2), ('a123',3), ('a124',4), ('a123',5); /* ('A123',2), ('A124',5), ('B123',6), ('B124',8); */
10 rows affected
 hidden batch(es)


select * from TableX;
col_A col_B
b123 10
b124 20
b123 30
b124 40
b123 50
a123 1
a124 2
a123 3
a124 4
a123 5
 hidden batch(es)


select col_A, sum(col_B) as col_B from tableX where col_B>0 group by col_A -- union all select 'subtotal : ' + substring(col_A,1,1) as col_A, sum(col_B) as col_B from tableX where col_B>0 group by substring(col_A,1,1) -- union all select 'total' as col_A, sum(col_B) as col_B from tableX where col_B>0
col_A col_B
a123 9
a124 6
b123 90
b124 60
subtotal : a 15
subtotal : b 150
total 165
 hidden batch(es)