Hi could anyone kindly help me in forming a query to display as follows:
Suppose i have a table with 3 columns and values in it as follows :
subject exam_month marks
History jan 20
History feb 40
Maths jan 40
English feb 60
History jan 20
Now i want to display the total of marks obtained in jan for every sub. the problem i am facing is i need to display the subject name with a value 0 even if the subject is not present in Jan. So my output need to be like
subject marks
History 40
Maths 40
English 0
Please help me in forming a query to get the desired output.
The query i had used is
select distinct(subject) , isnull( sum(marks), 0) from sample_table where exam_moth = 'jan' group by subject;
But the output i got is :
History 40
Maths 20
Note: English does not get displayed