sir i have a query ..in it am getting two values thatis total attended and right answer
select count(a.useranswer) as tot,(select count(c.useranswer) from Quiz_response as c inner join quiz_answer as d on c.qid =d.qid where c.mailid='nas@g.nbnh' and c.compid=1 and d.status=1 and c.useranswer = d.aid) as Rans from Quiz_response as a inner join
quiz_answer as b on a.qid =b.qid where a.mailid='nas@g.nbnh' and a.compid=1 and b.status=1
total attended=tot
right answer=rans
i want to calculate the percentage based on these two values in this query it self...is it possible?
(select count(a.useranswer) as tot,(select count(c.useranswer) from Quiz_response as c inner join quiz_answer as d on c.qid =d.qid where c.mailid='nas@g.nbnh' and c.compid=1 and d.status=1 and c.useranswer = d.aid) as Rans from Quiz_response as a inner join
quiz_answer as b on a.qid =b.qid where a.mailid='nas@g.nbnh' and a.compid=1 and b.status=1) T
select count(a.useranswer) as tot,(select count(c.useranswer) as total, (convert(varchar(max),(tot/total)*100)+'%' ) as percentage from Quiz_response as c inner join quiz_answer as d on c.qid =d.qid where c.mailid='nas@g.nbnh' and c.compid=1 and d.status=1 and c.useranswer = d.aid) as Rans from Quiz_response as a inner join quiz_answer as b on a.qid =b.qid where a.mailid='nas@g.nbnh' and a.compid=1 and b.status=1
insafkpm
Member
20 Points
120 Posts
calculate the percentage in Query itself
Aug 13, 2012 07:50 AM|LINK
sir i have a query ..in it am getting two values thatis total attended and right answer
select count(a.useranswer) as tot,(select count(c.useranswer) from Quiz_response as c inner join quiz_answer as d on c.qid =d.qid where c.mailid='nas@g.nbnh' and c.compid=1 and d.status=1 and c.useranswer = d.aid) as Rans from Quiz_response as a inner join quiz_answer as b on a.qid =b.qid where a.mailid='nas@g.nbnh' and a.compid=1 and b.status=1
total attended=tot
right answer=rans
i want to calculate the percentage based on these two values in this query it self...is it possible?
give mw a solution asap...
thanks in advance
urenjoy
Star
12073 Points
1810 Posts
Re: calculate the percentage in Query itself
Aug 13, 2012 09:03 AM|LINK
Try following:
Select T.tot, T.rans, T.rans*100/T.tot Perc
from
(select count(a.useranswer) as tot,(select count(c.useranswer) from Quiz_response as c inner join quiz_answer as d on c.qid =d.qid where c.mailid='nas@g.nbnh' and c.compid=1 and d.status=1 and c.useranswer = d.aid) as Rans from Quiz_response as a inner join quiz_answer as b on a.qid =b.qid where a.mailid='nas@g.nbnh' and a.compid=1 and b.status=1) T
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: calculate the percentage in Query itself
Aug 15, 2012 01:18 AM|LINK
Hi,
Just use the divide operator to deal with that——