Complex (for me) calculations on database

  • Thread starter Thread starter trettr
  • Start date Start date
T

trettr

Hi,
I need help to solve this problem.
I design a questionnarie and my client ask to a report of the results, much of
the answer are precompiled so I know the possibile value. For examples at
question A, and B the possible answer are YES or NO.

My problem is the I have to create a table in which I specify how much people
answers YES and NO at question A, and how much people answers YES and NO at
question B, and so on.

I'm able to recover only one value in a sql query.
<
Select count(A)
from MYtable
where A='YES'
So how can I recover all the sums for given values in every column?

Thank You very much
 
Hi,
I need help to solve this problem.
I design a questionnarie and my client ask to a report of the results, much of
the answer are precompiled so I know the possibile value. For examples at
question A, and B the possible answer are YES or NO.

My problem is the I have to create a table in which I specify how much people
answers YES and NO at question A, and how much people answers YES and NO at
question B, and so on.

I'm able to recover only one value in a sql query.
<
Select count(A)
from MYtable
where A='YES'

Try using the IIF function to generate a number that you can sum:

SELECT Sum(IIF([A] = 'YES', 1, 0)) AS YesOnA, Sum(IIF([A] = 'NO')) AS
NoOnA, ...
 
Try using the IIF function to generate a number that you can sum:
Sorry why the first part
Sum(IIF([A] = 'YES'
there is after the above condition
, 1, 0) while in the second part
Sum(IIF([A] = 'NO'
there isn't the same string?
I suspect it's a silly question but I know few about sql...

Thank you

SELECT Sum(IIF([A] = 'YES', 1, 0)) AS YesOnA, Sum(IIF([A] = 'NO')) AS
NoOnA, ...
 
Try using the IIF function to generate a number that you can sum:
Sorry why the first part
Sum(IIF([A] = 'YES'
there is after the above condition
, 1, 0) while in the second part
Sum(IIF([A] = 'NO'
there isn't the same string?

Because I was typing hastily and made a mistake. There should be.

The IIF() function has three arguments: a logical expression (i.e.
[A]='Yes'); a value to return if the expression is True; and a value
to return if it is False.

Sorry for the confusing and wrong answer - but it seems you figured
out the right one!
 
Back
Top