我需要做的是将这些结果插入到一个新表中,我将创建一个“匹配”按钮,它将查询两个表零售商和imovo,匹配将转到名为:matching的新表。
我需要的是为了避免重复..是从零售商表中删除并imovo匹配的行..
以下是我用来匹配的查询:
$data = mysql_query( "select r.`time`, r.`epos_id`, r.`date`,re.`location`,i.`user_id`,i.`mobile_number`,
i.`time`, i.`rbpos_id`, i.`date`
from retailer r
join rbpos_epos re on r.epos_id = re.epos_id
join imovo i on i.rbpos_id = re.rbpos_id
and addtime(r.`time`, '0:0:50') > i.`time`
and r.`time` < i.`time`
and r.`date` = i.`date`;
")
or die(mysql_error());
Print "<table border cellpadding=3>";
Print "<tr>";
Print "<th>Date:</th>
<th>Time</th>
<th>Location</th>
<th>User ID</th>
<th>Mobile Number</th>";
Print "</tr>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print " <td>".$info['date'] . "</td>
<td>".$info['time'] . " </td>
<td>".$info['location'] . " </td>
<td>".$info['user_id'] . " </td>
<td>".$info['mobile_number'] . " </td>
</tr>";
}
打印的行是我需要在匹配表中插入的行。 谢谢!
我试过了:
$data = mysql_query( "INSERT INTO Matching(date, time, location, user_id, phone)
SELECT
r.`date`,
`time`,
re.`location`,
i.`user_id`,
i.`mobile_number`
from retailer r
join rbpos_epos re on r.epos_id = re.epos_id
join imovo i on i.rbpos_id = re.rbpos_id
and addtime(r.`time`, '0:0:50') > i.`time`
and r.`time` < i.`time`
and
r。date
= i。date
;
“)
但是我得到了错误:
Column count doesn't match value count at row 1
答案 0 :(得分:0)
INSERT INTO Matching(date, time, location, user_id, phone)
SELECT
r.`date`,
`time`,
re.`location`,
i.`user_id`,
i.`mobile_number`
from retailer r
join rbpos_epos re on r.epos_id = re.epos_id
join imovo i on i.rbpos_id = re.rbpos_id
and addtime(r.`time`, '0:0:50') > i.`time`
and r.`time` < i.`time`
and r.`date` = i.`date`;
然后,当点击按钮INSERT
时,您必须执行此操作match
。
更新:如果要删除匹配的行。你可以DELETE
with JOIN
。类似的东西:
DELETE r, re, i
from retailer r
join rbpos_epos re on r.epos_id = re.epos_id
join imovo i on i.rbpos_id = re.rbpos_id
and DATE(r.`date`) = DATE(i.`date`);
这将删除所有三个表中的所有匹配行,如手册中所述:
对于多表语法,DELETE从每个tbl_name中删除 满足条件的行。
请注意:最好使用单列DATETIME
而不是两个独立的部分date
和time
,就像我在演示中所做的那样。然后你可以使用MySQL日期和时间函数来控制它们,就像我在连接条件DATE(r.date) = DATE(i.date)
中所做的那样。