考虑以下输入
Country1 Country2
A Z
B Y
C X
D W
X C
W D
A Z
我想将往返行程视为一体来对数据进行分组。例如:将C到X和X到C视为1。
Country1 Country2 Count of Trip
A Z 2
B Y 1
C X 1
D W 1
如何在查询中将往返行程分组在一起。
with cte as (
select
case when Country1 < Country2 then Country1 else Country2 end as Country1,
case when Country1 < Country2 then Country2 else Country1 end as Country2
from Table1
)
select
Country1, Country2, count(*)
from cte
group by Country1, Country2
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句