"Peter J. Schoenster" wrote:
> 
> Hello,
> 
> I will admit I have not done as much homework as perhaps I should.
> (using mysql 3.21.33b and perl5.004_04 built for i386-bsdos)
> 
> I have a voting script. Each time someone votes I insert values for
> the following:
> 
> refer  remote_addr cookie day  time ad
> 
> where 'ad' is what they voted for.
> 
> And then I show the current results of the voting.  This is where I
> think I am using an inefficient solution.
> 
> my $sql = "SELECT ad from superbowl";
> my($all,$rows) = $db->read("$dbase","$table","$sql");
> 
> foreach  my $line (@$all) {
>         my($ad) = @$line;
>         $count{$ad}++;
> }
> 
> and then I iterate:
> 
> foreach my $name (sort {$count{$b} <=> $count{$a}} keys %count) {
> 
> I think I can bypass the need for the hash and then sorting on the
> hash if I use the proper sql statement.
> 
> Am I correct? Would a better sql statement avoid the hash stuff?
> What book would anyone recommend to beef up my comprehension of sql?
> 
> Thanks,
> 
> Peter

Hi Peter

Sorry, but your db structure is unclear.
What do you actually search for?

I assume ad is a reference to the thing voted for (not the count of votes).
Further I assume you want to count how many lines in superbowl there are for each 
thing.
Then it is something like:
SELECT ad, count(*) FROM superbowl GROUP BY ad

Tschau
Christian

-----------------------------------------------------------
Send a mail to [EMAIL PROTECTED] with
unsubscribe mysql [EMAIL PROTECTED]
in the body of the message to unsubscribe from this list.

Reply via email to