[DB-SIG] Help on this query
Andy Todd
andy47@halfcooked.com
Wed, 05 Jun 2002 11:57:40 +1000
Titu Kim wrote:
> Hi there,
> I have two unrelated tables A and B which store
> different data. Let say the followings are the table
> schemas,
>
> Table A
> ID number,
> Date number,
> EarnA number
>
> Table B
> ID number,
> Date number,
> EarnB number
>
> ID in Table A and Table B is the same data. Assume
> Date in Table A and Table B is in number format. I can
> get EarnA from Table A with this query
>
> Select sum(EarnA) from TableA
> where ID=XX and Date between mmm and nnn;
>
> Similar for TableB i can get EarnB
> Select sum(EarnA) from TableB
> where ID=XX and Date between mmm and nnn;
>
> The number of rows in TableA and TableB are different
> and EarnA and EarnB are two different data. Now if i
> want to show EarnA and EarnB in one query for the same
> ID in both Tables, how can i do this? Table schemeas
> are simplified for discussion purposes.
>
> Thanks.
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com
>
>
> _______________________________________________
> DB-SIG maillist - DB-SIG@python.org
> http://mail.python.org/mailman/listinfo/db-sig
>
Try the following SQL statement;
SELECT sum(A.EarnA), sum(B.EarnB)
FROM TableA A, TableB B
WHERE B.id = A.id
This is bog standard SQL so I'd suggest you also take a look at a
tutorial
(http://directory.google.com/Top/Computers/Programming/Languages/SQL/FAQs,_Help,_and_Tutorials/?tc=1)
which may provide answers your questions more quickly than this mailing
list ;-)
Regards,
Andy
--
----------------------------------------------------------------------
From the desk of Andrew J Todd esq - http://www.halfcooked.com