Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have issue and i dont knw how to solve this issue help me to do this ....
this is data saved in my sql database

--------------------
ID | BloodGroup
--------------------
1 | A
2 | B
3 | A
4 | AB
5 | B
6 | O
7 | A
8 | AB

but my representation of data is totally different how i can perfom this kind of operation.

----------------------------------------
A | B |AB| O
----------------------------------------
3 | 2 |2 | 1
Posted

1 solution

Try this:
SQL
SELECT  A,B,AB,O
FROM
(SELECT bloodgroup  FROM table1) AS src
PIVOT
(
  COUNT(bloodgroup) FOR bloodgroup IN (A,B,AB,O)
)AS piv
 
Share this answer
 
Comments
Tarun Jaiswal 1-Apr-14 13:20pm    
thx you sir for solving my prob can you plz again solve this query with little modification this time i want to sum BloodGroup and show Total

----------------------------------------
A | B |AB| O | Total
----------------------------------------
3 | 2 |2 | 1 | 8
Peter Leow 1-Apr-14 20:52pm    
Good morning, just woke up and saw your message. Suggest you post it as a new question, and message me.
Tarun Jaiswal 2-Apr-14 0:56am    
this is link where i posted my question

http://www.codeproject.com/Questions/753317/How-I-Can-I-Sum-Bloodgroup-And-Show-Total-In-Datag
Peter Leow 2-Apr-14 1:00am    
answered.
Tarun Jaiswal 2-Apr-14 1:53am    
thx

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