使用PHP将下一行字段添加到mySQL的上一行

时间:2016-03-24 13:41:16

标签: php mysql

我有一个带有unix时间戳,userID,Long和lat的表。我想从下一行复制Long和Lat的值,并将它们添加到该行。请参阅下文。

<table style="width: 645px;" border="0" cellspacing="0" cellpadding="0">
  <colgroup>
    <col width="140" />
    <col width="57" />
    <col span="7" width="64" />
  </colgroup>
  <tbody>
    <tr>
      <td class="xl66" width="140" height="21">Unix Time Stamp</td>
      <td class="xl66" width="57">&nbsp;</td>
      <td class="xl66" width="64">Long</td>
      <td class="xl66" width="64">&nbsp;</td>
      <td class="xl66" width="64">Lat</td>
      <td class="xl66" width="64">&nbsp;</td>
      <td class="xl66" width="64">&nbsp;</td>
      <td class="xl66" width="64">&nbsp;</td>
      <td class="xl66" width="64">&nbsp;</td>
    </tr>
    <tr>
      <td class="xl67" align="right" width="140" height="20">1458119939</td>
      <td class="xl77" width="57">&nbsp;</td>
      <td class="xl70" align="right">-26.2004</td>
      <td class="xl70">&nbsp;</td>
      <td class="xl70" align="right">28.01277</td>
      <td class="xl70">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="xl68" align="right" width="140" height="21">1458119940</td>
      <td class="xl77" width="57">&nbsp;</td>
      <td class="xl70" align="right">26.20654</td>
      <td class="xl70">&nbsp;</td>
      <td class="xl70" align="right">28.04565</td>
      <td class="xl70">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="xl68" align="right" width="140" height="20">1458128756</td>
      <td class="xl71" width="57">&nbsp;</td>
      <td class="xl71" align="right" width="64">-29.0065</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td class="xl72" align="right" width="64">29.88437</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="xl68" align="right" width="140" height="20">1458128757</td>
      <td class="xl71" width="57">&nbsp;</td>
      <td class="xl71" align="right" width="64">-29.0067</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td class="xl72" align="right" width="64">29.88465</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="xl68" align="right" width="140" height="20">1442829381</td>
      <td class="xl71" width="57">&nbsp;</td>
      <td class="xl71" align="right" width="64">-29.0064</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td class="xl72" align="right" width="64">29.88458</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="xl68" align="right" width="140" height="21">1442829397</td>
      <td class="xl71" width="57">&nbsp;</td>
      <td class="xl73" align="right" width="64">-29.0062</td>
      <td class="xl78" width="64">&nbsp;</td>
      <td class="xl74" align="right" width="64">29.88436</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="xl69" align="right" width="140" height="21">1442830988</td>
      <td class="xl73" width="57">&nbsp;</td>
      <td class="xl75" align="right" width="64">-26.2065</td>
      <td class="xl79" width="64">&nbsp;</td>
      <td class="xl76" align="right" width="64">28.04565</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="20">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="20">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="xl65" colspan="3" height="20">Query Result needs to look like</td>
      <td class="xl65">&nbsp;</td>
      <td class="xl65">&nbsp;</td>
      <td class="xl65">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="xl66" height="21">Unix Time Stamp</td>
      <td class="xl66">&nbsp;</td>
      <td class="xl66">Long</td>
      <td class="xl66">&nbsp;</td>
      <td class="xl66">Lat</td>
      <td class="xl66">&nbsp;</td>
      <td class="xl66">LongB</td>
      <td class="xl66">&nbsp;</td>
      <td class="xl66">LatB</td>
    </tr>
    <tr>
      <td class="xl67" align="right" width="140" height="20">1458119939</td>
      <td class="xl77" width="57">&nbsp;</td>
      <td class="xl70" align="right">-26.2004</td>
      <td class="xl70">&nbsp;</td>
      <td class="xl70" align="right">28.01277</td>
      <td class="xl70">&nbsp;</td>
      <td class="xl70" align="right">26.20654</td>
      <td class="xl70">&nbsp;</td>
      <td class="xl70" align="right">28.04565</td>
    </tr>
    <tr>
      <td class="xl68" align="right" width="140" height="20">1458119940</td>
      <td class="xl77" width="57">&nbsp;</td>
      <td class="xl70" align="right">26.20654</td>
      <td class="xl70">&nbsp;</td>
      <td class="xl70" align="right">28.04565</td>
      <td class="xl70">&nbsp;</td>
      <td class="xl71" align="right" width="64">-29.0065</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td class="xl72" align="right" width="64">29.88437</td>
    </tr>
    <tr>
      <td class="xl68" align="right" width="140" height="20">1458128756</td>
      <td class="xl71" width="57">&nbsp;</td>
      <td class="xl71" align="right" width="64">-29.0065</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td class="xl72" align="right" width="64">29.88437</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td class="xl71" align="right" width="64">-29.0067</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td class="xl72" align="right" width="64">29.88465</td>
    </tr>
    <tr>
      <td class="xl68" align="right" width="140" height="20">1458128757</td>
      <td class="xl71" width="57">&nbsp;</td>
      <td class="xl71" align="right" width="64">-29.0067</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td class="xl72" align="right" width="64">29.88465</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td class="xl71" align="right" width="64">-29.0064</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td class="xl72" align="right" width="64">29.88458</td>
    </tr>
    <tr>
      <td class="xl68" align="right" width="140" height="21">1442829381</td>
      <td class="xl71" width="57">&nbsp;</td>
      <td class="xl71" align="right" width="64">-29.0064</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td class="xl72" align="right" width="64">29.88458</td>
      <td class="xl77" width="64">&nbsp;</td>
      <td class="xl73" align="right" width="64">-29.0062</td>
      <td class="xl78" width="64">&nbsp;</td>
      <td class="xl74" align="right" width="64">29.88436</td>
    </tr>
    <tr>
      <td class="xl68" align="right" width="140" height="21">1442829397</td>
      <td class="xl71" width="57">&nbsp;</td>
      <td class="xl73" align="right" width="64">-29.0062</td>
      <td class="xl78" width="64">&nbsp;</td>
      <td class="xl74" align="right" width="64">29.88436</td>
      <td class="xl78" width="64">&nbsp;</td>
      <td class="xl75" align="right" width="64">-26.2065</td>
      <td class="xl79" width="64">&nbsp;</td>
      <td class="xl76" align="right" width="64">28.04565</td>
    </tr>
  </tbody>
</table>

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

SELECT timestamp, userID, Long, Lat, Long as LongB, Lat as LatB FROM table

我认为你的意思是列而不是行