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 > Database Server Software > DB2 > select count (*) distinct on multiple cols

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-31-06, 10:26
fab01 fab01 is offline
Registered User
 
Join Date: Mar 2006
Posts: 17
Question select count (*) distinct on multiple cols

Hi everybody. (MVS / platinum / spufi / db2v7)
I have a query to ask you
My table named TABLE has these colums in the index
- TABLE_CLIENT_NAME
- TABLE_CLIENT_CARS
- TABLE_CLIENT_BILL_NUMBER
For example we can have
DUDE / PORSCHE / 001
DUDE / PORSCHE / 002
DUDE / PORSCHE / 003
DUDE / FERRARI / 001
DUDE / MASERATI /001
MIKE / BUICK / 001
MIKE / BUICK / 002
PAM / CORVETTE / 001
I want to know the number of rows of this TABLE
GROUP BY TABLE_CLIENT_NAME and TABLE_CLIENT_CAR
The query should gave me 5
I try to make select count(*) from (select distinct (table_client_name, table_client_cars) from TABLE)
Thanks for your reply
Reply With Quote
  #2 (permalink)  
Old 10-31-06, 12:41
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
This should work:

select count(*) from
(select distinct table_client_name, table_client_cars from TABLE) A
Reply With Quote
  #3 (permalink)  
Old 11-01-06, 02:39
fab01 fab01 is offline
Registered User
 
Join Date: Mar 2006
Posts: 17
It works fine !!
Thank you so much.

I don't understand why should we type the "A" at the end of the query.
Reply With Quote
  #4 (permalink)  
Old 11-01-06, 03:07
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
If you use a nested table expression, you have to add a correlation name.
It doesn't matter what the name is ( "A" or "HUGO" or "THISISANAME" or whatever you want ) but you have to add it for syntax reasons.
Reply With Quote
  #5 (permalink)  
Old 11-03-06, 06:05
fab01 fab01 is offline
Registered User
 
Join Date: Mar 2006
Posts: 17
Thanks for th explanation
Cheers
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