|
I am running a market survey and all the survey data is saved in the database ,i need a query for counting the number of rows in which option "1" is selected for question "1" , option "2" for question "1" and so on for all questions and options....i need to specify few conditions here ,i have to match distinct ID's of 3 database tables and display the result for each particular ID...i have written sample query but its not showing results with value as'0'
select opt1.question_no, opt_num1, opt_num2
from
(select question_no, count(option_number) opt_num1, stm.survey_id survey_id
from SURVEY_TXN_DATA std
, survey_txn_master stm,survey_master sm
where stm.survey_id = sm.survey_id
and stm.survey_txn_master_rowid = std.survey_txn_master_rowid
and stm.survey_id = 6
and option_number = 1
group by question_no,stm.survey_id) as opt1,
(select question_no, count(option_number) opt_num2, stm.survey_id survey_id
from SURVEY_TXN_DATA std
, survey_txn_master stm,survey_master sm
where stm.survey_id = sm.survey_id
and stm.survey_txn_master_rowid = std.survey_txn_master_rowid
and stm.survey_id = 6
and option_number = 2
group by question_no,stm.survey_id) as opt2
where opt1.survey_id = opt2.survey_id
and opt1.question_no = opt2.question_no
group by opt1.question_no ,opt_num1
, opt_num2
|
|
|
|
|
|
|
// |