oracle 2 个不同列的计数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5677665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Count of 2 distinct columns
提问by SouravM
How can I get the count of 2 columns such that there are distinct combinations of two columns?
如何获得 2 列的计数,以便有两列的不同组合?
Select count(distinct cola, colb)
回答by Quassnoi
SELECT COUNT(*)
FROM (
SELECT DISTINCT a, b
FROM mytable
)
回答by Chandu
SELECT COUNT(1)
FROM (
SELECT DISTINCT COLA, COLB
FROM YOUR_TABLE
)
回答by Geordee Naliyath
Another way of doing it
另一种方法
SELECT COUNT(DISTINCT COLA || COLB)
FROM THE_TABLE
回答by James Black
SELECT (select count(cola) from ...), (select count(colb) from ...) from ...
SELECT (select count(cola) from ...), (select count(colb) from ...) from ...
You may want to look at this:
你可能想看看这个:
You can put Distinct
in the subqueries, if you desire.
Distinct
如果您愿意,可以放入子查询。
回答by Sahil Chhabra
In Oracle DB, you can concat the columns and then count on that concatenated String like below:
在 Oracle DB 中,您可以连接列,然后计算连接后的字符串,如下所示:
SELECT count(DISTINCT concat(ColumnA, ColumnB)) FROM TableX;
In MySql, you can just add the columns as parameters in count method.
在 MySql 中,你可以在 count 方法中添加列作为参数。
SELECT count(DISTINCT ColumnA, ColumnB) FROM TableX;
回答by Tung Tran
SELECT COUNT(*)
FROM (
SELECT DISTINCT a, b
FROM mytable
) As Temp