How to count a column value only if another column value is present?

  • I have been tasked with creating a report that consists of if a student had a pre-misconception and a post-misconception of 3 different mathematical concepts. The database table includes the following columns for those values preMisc1, postMisc1, preMisc2, postMisc2, preMisc3, postMisc3 (all boolean values). It also includes the student's id number. My job is to calculate the following growth: "80% of students will show growth in two of three identified mathematical concepts each trimester.". There is the possibility that a student could have a post-misconception without having a pre-misconception. In that case I need to make sure that is not calculated into the growth.

    My first thought was to simply calculate the percentage increase or decrease between the pre and post for the 3 misconceptions. Reading the definition more closely I realized that will not work as if the student had a post-misconception and not a pre-misconception it should be counted, and the fact that I need calculate between the 3 misconceptions for each student because they only have to show growth in 2 of the 3.

    Having come to that conclusion I have realized this is more than I thought I would get into and am wondering if anyone would be willing to at least give me some pointers on how they would go about creating this report?

  • Your description is totally unclear, but I assume you need something like this:

    SELECT

    CASE WHEN

    (CASE WHEN preMisc1 = 1 AND postMisc1 = 1 THEN 1 ELSE 0 END +

    CASE WHEN preMisc2 = 1 AND postMisc2 = 1 THEN 1 ELSE 0 END +

    CASE WHEN preMisc3 = 1 AND postMisc3 = 1 THEN 1 ELSE 0 END) >= 2

    THEN 1

    ELSE 0

    END


    Alex Suprun

  • Alexander, thank you for reading through my rambling. Your solution was exactly what I needed. Still being new to SQL I think I sometimes miss the obvious solutions.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply