|
-
Jan 22nd, 2003, 08:14 PM
#1
Thread Starter
Registered User
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?
-
Jan 22nd, 2003, 08:38 PM
#2
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
-
Jan 22nd, 2003, 09:03 PM
#3
Thread Starter
Registered User
any expert here can give me the nice web site for me to learn SQL query?
-
Jan 22nd, 2003, 09:33 PM
#4
Fanatic Member
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 ***
-
Jan 22nd, 2003, 09:40 PM
#5
Frenzied Member
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
-
Jan 22nd, 2003, 10:04 PM
#6
Thread Starter
Registered User
thx lots ya..
anyway .. i have basic knowledge in SQL .. but im weak in joining tables.
-
Jan 26th, 2003, 08:19 PM
#7
Thread Starter
Registered User
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|