View previous topic :: View next topic
|
Author |
Message |
socker_dad
Active User
Joined: 05 Dec 2006 Posts: 177 Location: Seattle, WA
|
|
|
|
I am working with a Count Distinct query where the distinct value needs to be "calculated" on two fields: a date field and an alphanumeric field.
The combination of these two fields for a unique key.
I am at a loss as to how to put this in a DB2 query. I know how to do this on a single field, but not on multiple fields. My fields are CH07_06 and DT01.
I've thought of using another distinct in a subquery, but that results in erroneous counts as well. Any suggestions?
Code: |
SELECT COUNT(DISTINCT(CH07_06))
FROM TDLVAR
etc.
|
|
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi there,
I tried the below sql & its worked for me . I agree that this i snot efficent one bt will give you desired result
Code: |
SELECT COUNT(*) FROM (SELECT DISTINCT CH07_06, DT01 FROM TDLVAR) AS NEW_TAB; |
|
|
Back to top |
|
|
socker_dad
Active User
Joined: 05 Dec 2006 Posts: 177 Location: Seattle, WA
|
|
|
|
Thanks Ekta - that did the trick. (Funny how all my manuals never mentioned using two values in a Distinct phrase!) |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
Back to top |
|
|
|