Quote:
Originally posted by rydenius
Not all databases support COUNT(DISTINCT list) where 'list' is a comma separated list of more than one columns. For example DB2 and PGSQL does not (at least in the versions I've seen). Does anybody know a standard way to write a portable version of that expression, that works with most db's?
What I want to do:
SELECT COUNT(DISTINCT a, b) FROM c GROUP BY d;
...but without using multiple column arguments to COUNT DISTINCT.
Any ideas?
|
Oracle doesn't support that either. What one typically does, which I imagine would work on other DBMSs (but can't be sure) is:
SELECT COUNT(DISTINCT a||b) FROM c GROUP BY d;
If there are numbers and/or dates, these need to be converted to character first, which is where I imagine you will become DBMS-dependent again with date format masks etc.