比较数据以显示彼此1000之内的结果

时间:2022-12-21 11:25:54

I currently have a sample table as below:

我目前有一个样本表如下:

  Country    |  Sessions
   US             1000  
   UK              500  
   US             2000  
   BR             7000
   CA             3000

The MySQL query I am looking help with is to get the output as follows, that displays the country name pairs that are within '1000' of each other

我正在寻求帮助的MySQL查询是获取如下输出,显示彼此在'1000'范围内的国家/地区名称对

Sample Output:

样本输出:

  Country_A    |  Country_B
   US               UK   
   UK               US  
   US               CA  
   CA               US

Thanks for your help!

谢谢你的帮助!

1 个解决方案

#1


1  

SELECT a.Country AS Country_A
     , b.Country AS Country_B
  FROM my_table a
  JOIN my_table b ON ABS(a.Sessions - b.Sessions) <= 1000
   AND a.Country <> b.Country;

#1


1  

SELECT a.Country AS Country_A
     , b.Country AS Country_B
  FROM my_table a
  JOIN my_table b ON ABS(a.Sessions - b.Sessions) <= 1000
   AND a.Country <> b.Country;