Rember that the sum function sums the total of all
of the colum specified.  Is there multiple rows where
the same c.cid_no occurs many times?  If so, then you
need a "group by" and "having" clauses.  If not, 
then you don't need the sum function.

With a group by, it'd look like this... I think ...

  select c.cid_no, c.name
    from carrier c, loads l
   where c.cid_no = l.cid_no
  group by c.cid_no
  having sum(l.amount) > 600

Remember that column and tablenames are *spefic* to the
definition of the table.  So, a columnname of C.CID_NO 
isn't the same as defined as c.cid_no.  And that a 
tablename of "CARRIER" isn't the same as "carrier".  To
see specifically what the columnname case sensitive
spellings are do a "show columns on tablename".

Without a group by, because each c.cid_no only appears
once in the carrier table, it'd be a regular query without
any summing being performed on a column.


> -----Original Message-----
> From: Richard Reina [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 09, 2002 1:11 PM
> To: [EMAIL PROTECTED]
> Subject: mysql query
> 
> 
> I am trying to write a query that gets the name of every 
> carrier who has done more than $600 
> in loads.  Can anyone help?
> 
>     SELECT c.name
>     FROM carrier c, loads l
>     WHERE c.CID_NO = l.CID_NO
>     AND SUM(l.amount > 600);
> 
> This, unfortunately does not work.
> 
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail 
> <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
> 

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to