Results 1 to 7 of 7

Thread: Sql Query

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jul 2002
    Posts
    119

    Sql Query

    hi all..

    let say i have 2 table named customer and sales

    Customer
    Id Name Date ................
    ------------------------------------------------
    5 ABC 1/1/03
    6 DEF 1/5/03
    7 GHI 1/8/03
    8 JKL 1/10/03


    Sales
    Customer_Id Product Quantity Amout
    --------------------------------------------------------
    5 ABC 1 10.00
    5 ABC 2 20.00
    5 ABC 3 30.00
    6 ABC 4 40.00
    6 ABC 6 50.00
    7 ABC 7 60.00
    8 ABC 8 70.00
    8 ABC 9 80.00


    let's say now i wan to select data Between 1/1/03 and 1/5/03
    wat data field i wan to retrive is

    Customer.Id Customer.Name Total Sales (Total row in Sales),
    Total Quantity, and Amount

    so.. my data should be
    Id Name Total_Sales Quantity Amount
    --------------------------------------------------------
    5 ABC 3 6 60.00
    6 DEF 2 10 90.00

    so.. anyone can help me how to write those SQL coding?

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Off the top of my head - something similar should work.

    Code:
    Select 
       C.Customer_Id,
       C.Customer_Name,
       Count(S.Customer_Id) as TotalSalesCount,
       Sum(Quantity) as TotalQuantity,
       Sum(Amount) as TotalAmount
    
    From Customers C Join Sales S On C.Customer_Id = S.Customer_Id
    
    Where C.Date Between 1/1/03 and 1/5/03 
    Group By C.Customer_Id, C.Customer_Name

  3. #3

    Thread Starter
    Registered User
    Join Date
    Jul 2002
    Posts
    119
    any expert here can give me the nice web site for me to learn SQL query?

  4. #4
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    Originally posted by hao_han
    any expert here can give me the nice web site for me to learn SQL query?
    before you go to website, I think you can learn SQL Query for the first time from your SQL Help.
    I learn mostly from SQL Help, nd I can do all my daily task at office.

    ___________
    *** Wille ***

  5. #5
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Originally posted by hao_han
    any expert here can give me the nice web site for me to learn SQL query?
    http://www.w3schools.com/sql/default.asp

  6. #6

    Thread Starter
    Registered User
    Join Date
    Jul 2002
    Posts
    119
    thx lots ya..

    anyway .. i have basic knowledge in SQL .. but im weak in joining tables.

  7. #7

    Thread Starter
    Registered User
    Join Date
    Jul 2002
    Posts
    119
    how to do if i need relation for 3 tables?
    refer to my 1st post

    i need to query the product name from my Product Table?

Posting Permissions

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



Click Here to Expand Forum to Full Width