If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > how to ? GROUP BY?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-07-04, 04:56
zorzi011 zorzi011 is offline
Registered User
 
Join Date: Dec 2004
Posts: 2
how to ? GROUP BY?

Hi,
I have a problem with the GROUP BY clause in SQL 2000.

I have 3 tables in db:

1. INVESTORS with fields (idinvestor, name, address etc) ,
2. CONTRACTS with fields (idcontract, idinvestor, contnr, date, etc.) and
3. PAYMENTS with fields (idpayment, idcontract, dateofpayment, amount etc.).

I want to make a report of payments and group them by idcontract, like this :

SELECT idpayment, idcontract, dateofpayment, SUM(amount) FROM PAYMENTS GROUP BY idcontract

but I would like to join tables CONTRACTS and INVESTORS also, so I can have number of the CONTRACT (contnr) and name of the INVESTOR (name) in the same report.
I don't know should I use nested query or JOIN command and if anyone has any example...... ?

Thank you in advance.
Reply With Quote
  #2 (permalink)  
Old 12-07-04, 06:19
Madhivanan Madhivanan is offline
Registered User
 
Join Date: Oct 2003
Posts: 357
Thumbs up

Hi, try this
Code:
SELECT P.idpayment, P.idcontract, P.dateofpayment, 
SUM(P.amount),I.Name, C.Contnr FROM PAYMENTS P, Investors I ,
Contracts C where P.idContract=C.idContract and C.idinvestor=I.idInvestor
GROUP BY P.idpayment, P.idcontract, P.dateofpayment, I.Name, C.Contnr
Madhivanan

Last edited by Madhivanan; 12-07-04 at 06:23.
Reply With Quote
  #3 (permalink)  
Old 12-07-04, 06:51
zorzi011 zorzi011 is offline
Registered User
 
Join Date: Dec 2004
Posts: 2
thank you man
a lot
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On