#!/usr/local/bin/perl use lib '/usr/local/ct.com/lib'; use CTC::DB; #------------------------------------------------------------------------------ { my $table = 'tech_sched.student_enrollment_statuses'; $DBH = CTC::DB->connect(); &report1($table,35,36,11); print "----------------\n"; &report2($table,35,36,11); } #------------------------------------------------------------------------------ sub report1 { my $table = shift @_; my @statusids = @_; my $sql = "SELECT COUNT(*) FROM $table WHERE statusid = ?"; my $sth = $DBH->prepare($sql); foreach my $statusid (sort @statusids) { $sth->execute($statusid); my ($count) = $sth->fetchrow_array; print "$statusid = $count\n"; } } #------------------------------------------------------------------------------ sub report2 { my $table = shift @_; my @statusids = @_; my $sql = "SELECT statusid FROM $table WHERE statusid IN (" . join(',',@statusids) . ")"; my $sth = $DBH->prepare($sql); $sth->execute; my %count; while (my ($statusid) = $sth->fetchrow_array) { $count{$statusid}++; } foreach my $statusid (sort @statusids) { my $count = $count{$statusid}++ || 0; print "$statusid = $count\n"; } }