Counting a value only if it appears more than once in a table.

Posted 4 months ago by twoarmtom

I'm having trouble getting a count based on a special condition.

Basically, a "completed competency" is one that receives an evaluation of 3 at least two times. The following code works for counting how many distinct competencies have an evaluation of 3, but I want it to only count them if the distinct competency_id has an evaluation of 3 at least twice in the database for the specified student. Any suggestions?

$completed_competencies = DB::table('submitted_competencies')
                                ->where('student_id', 202)
                                ->where('evaluation', 3) // I want this to happen twice for the same competency_id before it is counted.

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.