[英]How to count distinct values over all rows 2 columns
我有2列,並且我希望在整個BOTH列中查找所有不同值的計數,而不僅僅是兩列中的同一行。 IE此處的不同值計數為9,因為1000、5000、7000和8000僅包含一次。
x y
1000 NULL
2000 1000
3000 1000
4000 1000
5000 1000
6000 5000
7000 5000
8000 7000
9000 8000
您可以取消數據透視和計數:
select count(distinct x)
from ((select x from t) union all
(select y from t)
) t;
就是說,看起來第一列是唯一的,並且具有您想要的信息,所以也許您只是想要:
select count(*)
from t;
要么:
select count(distinct x)
from t;
聯盟是要走的路
Select count(*) from(Select x from
table tx
union
Select y from table ty) ;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.