如何 select 对多列进行不同计数?
How do I select distinct count over multiple columns?
如何 select 对多列进行不同的计数?
SELECT COUNT(DISTINCT col1, col2, col3) FROM table;
在 DB2 中是否有与此等效的工作?
有多个选项:
select count(*) from
(select distinct col1, col2, col3 FROM table) t
另一种方法是通过 CONCAT 合并列:
select count(distinct col1 || col2 || col3) from table
第一个选项更干净(而且可能更快)。
select count(distinct col1 || '^' || col2 || '^' || col3) from table
避免在连接过程中出现问题,例如 1 || 11 与 11 || 相同1.
如何 select 对多列进行不同的计数?
SELECT COUNT(DISTINCT col1, col2, col3) FROM table;
在 DB2 中是否有与此等效的工作?
有多个选项:
select count(*) from
(select distinct col1, col2, col3 FROM table) t
另一种方法是通过 CONCAT 合并列:
select count(distinct col1 || col2 || col3) from table
第一个选项更干净(而且可能更快)。
select count(distinct col1 || '^' || col2 || '^' || col3) from table
避免在连接过程中出现问题,例如 1 || 11 与 11 || 相同1.