-1

I'm getting sql error for the below select

(select ((Select count(student_hash)from ssa.survey_results where question_master_id in (22)and center_id=101100 and answer_master_id in (95,96))*100/
(select (select case when exists((Select * from ssa.survey_results where question_master_id in (22)))then(Select count(student_hash)
from ssa.survey_results where question_master_id in (22))else 1 end)))As QUESTION22PERCENTAGE  from ssa.survey_results cd group by QUESTION22PERCENTAGE)Q22Percentage,

(select ((Select count(student_hash)from ssa.survey_results where question_master_id in (22)and answer_master_id in (95,96))*100/
(select (select case when exists((Select * from ssa.survey_results where question_master_id in (22)))then(Select count(student_hash)
from ssa.survey_results where question_master_id in (22))else 1 end)))As QUESTION22PERCENTAGE  from ssa.survey_results cd group by QUESTION22PERCENTAGE)Q22oPercentage,
(SELECT CASE WHEN Q22Percentage = Q22oPercentage THEN 'SAME'
            WHEN  Q22Percentage  > Q22oPercentage THEN 'BETTER'
            WHEN  Q22Percentage  < Q22oPercentage THEN 'WORSE'
            ELSE 'No comparison' END AS comparison)
            from  ssa.survey_results 
            group by Q22Percentage,Q22oPercentage;

I appreciate your help

ERROR: column "q22percentage" does not exist LINE 10: (SELECT CASE WHEN Q22Percentage = Q22oPercentage THEN 'SAME' ^

Evan Carroll
  • 63,051
  • 46
  • 242
  • 479
Dango
  • 1
  • 4
  • select (select ((Select count(student_hash)from ssa.survey_results where question_master_id in (22)and center_id=101100 and answer_master_id in (95,96))100/ (select (select case when exists((Select from ssa.survey_results where question_master_id in (22)))then(Select count(student_hash) from ssa.survey_results where question_master_id in (22))else 1 end)))As QUESTION22PERCENTAGE from ssa.survey_results cd group by QUESTION22PERCENTAGE)Q22Percentage,

    and

    – Dango Jan 20 '17 at 18:02
  • (select ((Select count(student_hash)from ssa.survey_results where question_master_id in (22)and answer_master_id in (95,96))100/ (select (select case when exists((Select from ssa.survey_results where question_master_id in (22)))then(Select count(student_hash) from ssa.survey_results where question_master_id in (22))else 1 end)))As QUESTION22PERCENTAGE from ssa.survey_results cd group by QUESTION22PERCENTAGE)Q22oPercentage from ssa.survey_results group by Q22Percentage,Q22oPercentage; – Dango Jan 20 '17 at 18:02
  • I get results -- but when I'm adding case statement I'm getting error – Dango Jan 20 '17 at 18:03
  • Basically when i run both select statements -- i get the results -- only in CASE statements those Q22 and Q22o which are derived values ( which are not physically present in the table ssa.survey_results giving issue -- having said how do we compare both derived values to assign some values ? CASE WHEN Q22Percentage = Q22oPercentage THEN 'SAME'---- first we are getting sum of values and then comparison -- Thanks – Dango Jan 20 '17 at 19:01

1 Answers1

1

The table ssa.survey_results does not have a column Q22Percentage

How much clearer can that message get?

Evan Carroll
  • 63,051
  • 46
  • 242
  • 479