October 9, 2007 at 5:57 pm
I know this is an easy thing but I'm just learning and am self taught.
I have a table of data that contains a lot of True/False records. What is a good way to come up with what percentage of a column is answered True?
This result will then be displayed in a web page most likely in a Gridview using visual web developer.
Thanks in advance
Mike
October 10, 2007 at 12:09 am
SELECT QuestionID,
Yes,
Yes / Answers,
No,
No / Answers,
Answers
FROM (
SELECT QuestionID,
SUM (CASE WHEN Answer = 1 THEN 100.0 ELSE 0.0 END) AS Yes,
SUM(CASE WHEN Answer = 0 THEN 100.0 ELSE 0.0 END) AS No,
COUNT(*) AS Answers
FROM Questions
GROUP BY QuestionID
) AS d
N 56°04'39.16"
E 12°55'05.25"
October 10, 2007 at 9:25 am
Maybe the caffeine just wore off - but why are you adding up increments of 100?
....
sum(Case when Answer=1 then 100.0 else 0 end),
....
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
October 11, 2007 at 1:11 am
A possible alternative is
SELECTQuestionID,
COUNT(*) AS CountRows,
(CAST(COUNT(*) AS float) / (SELECT COUNT(*) FROM dbo.Answers)) * 100 AS PercentRows
FROMdbo.Answers
GROUP BY
QuestionID
October 11, 2007 at 2:10 am
Instead of return 0.45 which in mathematical term is 45%, the algorithm returns 45.0, which most beginners find more appealing.
N 56°04'39.16"
E 12°55'05.25"
October 11, 2007 at 7:00 pm
Thank you for your reply and help.
I get most of it but I'm confused about this section
Yes,
Yes / Answers,
No,
No / Answers,
Answers
Could you (or anyone) elaborate on this part. Or tell me where I could learn about this.
October 11, 2007 at 7:19 pm
Thanks for the help. I do see I have to read up on what CAST means.
Is there a section on this site or another that can be used to learn about Keywords like that?
October 16, 2007 at 4:46 pm
BOOKS ONLINE is your best friend 🙂
* Noel
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply