* [EMAIL PROTECTED]
> Two tables
>
> 1. Clients
>       ClientID (Primary Key, Unsigned int , Auto_Increment)
>       Vehicle type            Char(200)
>       Vehicle Color              CHAR(200)
>
> 2. Service
>       ServiceID (Primary Key, Unsigned int , Auto_Increment)
>       ClientID                INT
>       ServiceDate             Date
>       InvoiceAmount           Char(200)
>
> 2 queries
>
> 1. I wish to total the invoice amount for the records from
> Service (between two dates)
> where the Clients.VehicleColour = 'Blue'

SELECT SUM(InvoiceAmount)
  FROM Service,Clients
  WHERE
    Service.ClientID=Clients.ClientID AND
    (ServiceDate BETWEEN '2002-01-01' AND '2002-01-31') AND
    VehicleColour = 'Blue';

<URL: http://www.mysql.com/doc/en/SELECT.html >
<URL: http://www.mysql.com/doc/en/JOIN.html >
<URL: http://www.mysql.com/doc/en/Comparison_Operators.html >

> 2. I wish get all the records from Service (between two dates) where the
> Clients.VehicleColour = 'Blue'

That's pretty much the same thing, except returning the Service row instead
of the sum of the invoice amount:

SELECT Service.*
  FROM Service,Clients
  WHERE
    Service.ClientID=Clients.ClientID AND
    (ServiceDate BETWEEN '2002-01-01' AND '2002-01-31') AND
    VehicleColour = 'Blue';

HTH,

--
Roger


---------------------------------------------------------------------
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