|
Posted by HaggMan on 07/13/06 17:22
I have two tables for holding questions and the corresponding answers
of several users.
Table 1 (matt_q as q):
id, secid, weight
Table 2 (matt_ans as a):
id, qid, userid, answer
Answer can be "Yes" or "No"
There are several sections (corresponding q.secid)
I'd like to get the sum of q.weight for all the entries in Table 1
where the corresponding a.answer (joined by qid=q.id) is "no" grouped
by q.secid
This is what I have so far:
select q.secid, sum(q.weight) from matt_q as q, matt_ans as a where
a.qid=q.id and a.answer='no' group by q.secid;
This works unless the user has not answered any questions with 'no.'
In that case, there is no row returned (because the sum is null). Is
there any way to get a sum of 0?
Sorry if this is confusing.
[Back to original message]
|