将 2 列中的精确串联值分组? [英] group exact Tandem values from 2 column?

查看:33
本文介绍了将 2 列中的精确串联值分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 2 列纬度和经度的表格,并且想要对 2 列上的 (just) 串联 值进行 GROUP 精确匹配.
表格行:

I have a table with 2 column latitude and longitude and want to GROUP exact match (just) tandem values on 2 columns.
Table Rows:

/* Points Table */
time    |lat    |long
113     |2.1    |5.8
114     |2.1    |5.6    -Set as Group
115     |2.1    |5.6    -Set as Group
116     |2.1    |5.6    -Set as Group
117     |2.1    |5.6    -Set as Group
118     |2.3    |5.2
119     |2.4    |5.3
120     |2.5    |5.3    -Set as Group
121     |2.5    |5.3    -Set as Group
122     |2.6    |5.3
123     |2.1    |5.6    -Set as Group
201     |2.1    |5.6    -Set as Group
202     |2.1    |5.6    -Set as Group
203     |2.5    |5.3

结果必须是:

/* Points Table */
time    |lat    |long
113     |2.1    |5.8
114     |2.1    |5.6    -Grouped as 1 with first tandem time
118     |2.3    |5.2
119     |2.4    |5.3
120     |2.5    |5.3    -Grouped as 1 with first tandem time
122     |2.6    |5.3
123     |2.1    |5.6    -Grouped as 1 with first tandem time
203     |2.5    |5.3

我只想对串联值进行分组,在上面我们有两个 2.1 & 的时间串联.5.6 值和组被拆分.(用于测试可以在 http://sqlfiddle.com/#!2/5d196 上工作).;)

I want to group just Tandem values , in above we have two time tandem of 2.1 & 5.6 values and group is splited. ( for testing can work on http://sqlfiddle.com/#!2/5d196 ). ;)

推荐答案

您可以使用 PHP 做到这一点:

You could do this using PHP:

$query = mysqli_query("SELECT time, lat, `long` FROM Points ORDER BY time");

// output header row
echo str_pad('time', 8) .'|';
echo str_pad('lat', 7) .'|';
echo "long\n";

$prevLat = $prevLong = '';
while ($row = mysqli_fetch_assoc($query)) {
    if ($row['lat'] === $prevLat && $row['long'] === $prevLong) {
        // if this row's lat and long values are the same as the
        // previous row's values, skip this row.
        continue;
    }

    $prevLat  = $row['lat'];
    $prevLong = $row['long'];

    echo str_pad($row['time'], 8) .'|';
    echo str_pad($row['lat'], 7) .'|';
    echo "{$row['long']}\n";
}

这是一个示例:http://codepad.org/c0SjA058

这篇关于将 2 列中的精确串联值分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆