Results 1 to 2 of 2

Thread: SQL query help

  1. #1
    Join Date
    Apr 2004

    Unanswered: SQL query help

    Hi Gurus,
    I'm a novice SQL programmer. I'm trying to write a SQL query
    and would appreciate any help. This is the jist of what I'm trying to do.
    Let's say I'm an customer (not my exact scenario, but close enough)
    I have all my billing history in a table, say BILL_HISTORY...

    I want to find out all the orders I have placed in the previous month (1 row for each order in this period) and
    the value of sum of all the orders that I placed.

    ie., something like this...

    bill_amt, sum (bill_amt)
    bill_date between <#start_date#> and <#end_date#>

    Now, the above query would give me a sum that is the amount ($$) ordered
    during the specified period (dates). However, my intention
    is to get total amount ordered for from the date I first purchased anything at

    How would you write a query?

    Your help is much appreciated.


  2. #2
    Join Date
    Dec 2003

    select person, bill_amt, view1.total_amt
    from bill_history, (select person, sum(bill_amt) total_amt
    from bill_history) view1
    where bill_history.person = view1.person
    and bill_date between <#start_date#> and <#end_date#>

    This will only give you information for people with transactions between <#start_date#> and <#end_date#>.


Posting Permissions

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