Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2007
    Location
    Manila, Philippines
    Posts
    132

    Unanswered: add the subtract the sum() of 2 table

    hi,
    sorry my title is wrong. subtract 2 tables.

    i know this is simple for you guys, but i cant find a way
    can anyone please help me...

    i want to subtract the sum() of my field from 2 tables.

    Code:
    SELECT amount as 'sum' FROM mafee_db.mafee_capital_tbl where acc_type = 'cash on hand'
    -
    SELECT sum(principal) as 'sum' FROM mafee_db.pawnshop_tbl where servicetype = 'pawn'
    thanks in advance
    Last edited by homer.favenir; 11-20-08 at 23:15.
    Take Nothing But Pictures;
    Leave Nothing But Footprints;
    Kill Nothing But Time;

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT ( SELECT amount 
               FROM mafee_db.mafee_capital_tbl 
              WHERE acc_type = 'cash on hand' )
         - ( SELECT sum(principal)
               FROM mafee_db.pawnshop_tbl
              WHERE servicetype = 'pawn' ) AS answer
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Oct 2007
    Location
    Manila, Philippines
    Posts
    132
    thanks, youre a great help
    Take Nothing But Pictures;
    Leave Nothing But Footprints;
    Kill Nothing But Time;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •