[英]Compare data to display results within 1000 of each other
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! 谢谢你的帮助!
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.