Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,

I got stuck in the following query, Kindly do the needful...

Following is my Table :
SQL
CREATE TABLE IF NOT EXISTS `exam_marks` (
  `emid` int(11) NOT NULL AUTO_INCREMENT,
  `eid` int(11) NOT NULL,
  `sid` int(11) NOT NULL,
  `mark` float NOT NULL,
  PRIMARY KEY (`emid`)
) 



And Data....

SQL
INSERT INTO `exam_marks` (`emid`, `eid`, `sid`, `mark`) VALUES
(1, 3, 28, 15),
(2, 3, 29, 2),
(3, 3, 30, 15),
(4, 3, 31, 14),
(5, 3, 32, 15),
(6, 3, 33, 6),
(7, 3, 34, 15),
(8, 3, 35, 15),
(9, 3, 36, 15),
(10, 3, 37, 10),
(11, 3, 38, 11),
(12, 3, 39, 12),
(13, 3, 40, 13),
(14, 3, 41, 14),
(15, 3, 42, 15),
(16, 3, 43, 16),
(17, 3, 44, 17),
(18, 3, 45, 18),
(19, 3, 46, 19),
(20, 3, 47, 20),
(82, 7, 29, 10),
(84, 7, 31, 10),
(86, 7, 33, 15),
(90, 7, 37, 22),
(91, 7, 38, 33),
(92, 7, 39, 22),
(93, 7, 40, 22),
(94, 7, 41, 22); 




Eid 3 means its regular Exam and Eid 7 means its remedial exam... I want to prepare following report :
**************************** output i want is as follow*********
Sid reg rem
28 15 Null
29 2 10
30 15 Null
..
..
..
..
..

Thanks in advance,
Posted
Comments
walterhevedeich 28-Nov-13 0:12am    
Tried anything?

This is one situation where CASE[^] would be helpful. Let's say you have a table with the following data:

User

ID Name    Age
1  Bob     18
2  Chelsey 22
3  Rick    16 


and you want a report that checks if the entries on the table are minors

Name   Minor


Using CASE, you can write the following query:

SQL
SELECT Name, 
CASE
   WHEN Age < 18 THEN 'Yes'
   ELSE 'No'
END As Minor
FROM User


Output will be

Name    Minor
Bob     No
Chelsey No
Rick    Yes
 
Share this answer
 
Comments
thatraja 28-Nov-13 1:21am    
Nice one. 5!
Sorry Walter, I forgot to reply your mail, I'll soon.
walterhevedeich 28-Nov-13 1:26am    
Thanks. It's OK. Hope you are doing fine there.
thatraja 28-Nov-13 1:28am    
Ofcourse, more than fine. Will PM with more details
I wrote following query... but it shows me only records exist in both :

SQL
select a.sid, a.mark as regmark, ifnull(b.mark,"") as remmark from exam_marks a, exam_marks b where a.sid = b.sid and a.eid=3 and b.eid=7


output :

sid	regmark	remmark
31	14	10
32	5	10
33	6	15


I want to include null values for column remmarks also.
 
Share this answer
 
v2
Comments
walterhevedeich 28-Nov-13 0:35am    
Next time, don't put it as solution if this is not the answer to your inquiry. Use Improve solution to update your question with recent information. I have provided an explanation on how you can accomplish it. It's by using CASE.
compad 28-Nov-13 1:26am    
Okey... Thanks for suggestions..
walterhevedeich 28-Nov-13 1:27am    
No problem.

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