Reply to SQL sum problem

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация