Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hello,
I have a table

slno Number Type
1 100 P
1 101 A
2 200 P
2 202 A

As per the requirement i need to display
Police : 100
Ambulance:101
Emergency Police : 200
Emergency Ambulance: 202

Please help me.
Posted
Comments
Prasad_Kulkarni 6-Jul-12 1:07am    
..and what you want?? where's your question?
Sandeep Mewara 6-Jul-12 1:49am    
Help with what! You ave not shared your issue and what you tried, where are you stuck!
rohit24c 6-Jul-12 7:18am    
case type when 'P' then 'Police:'
when 'A' then 'Ambulance' else 'Others'
but then results in Police:100 Ambulance:101 Police:200 Ambulance:201 but i want it like Police:100 Ambulance:101 Emergency Police:200 Emergency Ambulance:201 here in the table i need to filter it based on slno also that i am not able to do.

Please read this.[^] first.

What help you want. What exactly is your problem?
 
Share this answer
 
SQL
Select Police=sum(case when Type='P' then Number else 0 end),
       Ambulance=sum(case when Type='A' then Number else 0 end),
       EmergencyPolice=sum(case when (Type='E' or Type='P') then Number else 0 end),
       EmergencyAmbulance=sum(case when (Type='E' or Type='A') then Number else 0 end) from tableName
 
Share this answer
 

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