Click here to Skip to main content
16,022,752 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
id name manecount femalecount
1 OC 1 1

2 BC-a 4 5

3 BC-b 2 3

4 BC-c 1 2




now i want result like i have only one column BC in that i need total male and female count of BC-a, BC-b,BC-b
like this

id name manecount femalecount
1 OC 12 13

2 BC 7 10
Posted

Try this hope its useful or give some hint in right direction.

SQL
SELECT CAT,SUM(MC),SUM(FC) FROM (
select ID,LEFT(NAME,2) CAT,mc,FC from Table1) P
GROUP BY CAT
 
Share this answer
 
May this helps

SQL
CREATE TABLE BCounts
(ID INT IDENTITY,Bcon VARCHAR(10), Val1 INT, Val2 INT)
INSERT BCounts VALUES('OC',1,1),('BC-a',4,5),('BC-b',2,3),('BC-c',1,2)

SELECT LEFT(B.Bcon,2) Col1, SUM(B.Val1) Col2 ,SUM(B.Val2) Col2 FROM BCounts B
GROUP BY LEFT(B.Bcon,2)


Col1	Col2	Col3
BC	7	10
OC	1	1
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900