Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query

Status
Not open for further replies.

Sverre

Programmer
Feb 16, 2005
33
NO
I have a table with FK customersID and the fields Year (XXXX), Month (values 1 to 12) and amount. Each Customer can have several rows with the same year but different month and amount. Some customers have records for the month 1,2,3,4, but others only month 1,3 and so on.

What I like to do is to have one select Query that groups together to the customers and sum the amount, but only those costomers who have amounts registered in the same months as my spesially selected Customer.
For instance: customerID 34 has an amount in month 2,3, and 5. I what to group the other customers who also (and only) have amounts in the same three months (2,3 and 5).
It should all be done in one single Query from an .asp webpage.

Sverre

 
The syntax of the query will depend on your database engine. MS Access, SQL Server, etc., etc..

You will probably get a better response if you post in the forum for your specific database engine. You can search for the specific forum at the top of this page.

zemp
 
I am using MS SQL in this case.
By the way, I am new here so what should I do with the post. Can I move this tread to another forum or must I repost it?

Sverre
(Norwegian by the way - excuse my bad English)
 
Repost it in forum183.

You can also red flag this thread and explain to the site managment that it was in the wrong forum. The link to red flag is at the bottom of every post in the thread.

BTW welcome to Tek-Tips! We're glad to have you on board. When you get a chance read faq222-2244 for information on how to get the most from Tek-Tips.

zemp
 
Thank you!

I will stop this here, and repost to Forum183

Sverre
 
You probably want a query inside a query. Make one simple querry that has the month codes like 1,2,3,4 of the target customer. Then make another querry where the table records month is in the first querry results.

If you do not like my post feel free to point out your opinion or my errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top