如何在查询中将两个或多个表内部联接在一起?

时间:2019-04-25 07:35:57

标签: mysql sql

我想要结果的查询应该在我的customer_info表中得到更新。我确实知道表之间有任何关系,但是我必须使用内部联接来运行查询。请帮忙。

当前标签表

_reader_ID_|__tag_no__|__area |_maxtime_____
           |          |       |

Tag_logs表

reader_ID_|__tag_no__|timestamp___
          |          |       

Aisle_info表

reader_ID_|_area_|
          |      |      

customer_info表

name_|__email__|__reader_id |_tag_no|_area|_maxtime_
     |         |            |       |     |
INSERT INTO customer_info
SELECT aisle_info.reader_ID, tag_no, aisle_info.area, customer_info.name, TIMESTAMPDIFF(SECOND,MIN(timestamp),MAX(timestamp)) AS MAXTIME FROM tag_logs INNER JOIN aisle_info ON tag_logs.reader_ID = aisle_info.reader_ID AND customer_info INNER JOIN current_tags ON customer_info.name = customer_info.name 
WHERE tag_no = 3222813112261
  

1052-字段列表中的“ tag_no”列不明确

1 个答案:

答案 0 :(得分:0)

当一列多于一个表时,应添加表名,因此,假设tag_logs表中存在tag_no,请尝试tag_logs.tag_no

INSERT INTO customer_info
SELECT aisle_info.reader_ID
    , tag_logs.tag_no
    , aisle_info.area
    , customer_info.name
    , TIMESTAMPDIFF(SECOND,MIN(timestamp)
    ,MAX(timestamp)) AS MAXTIME 
FROM tag_logs 
INNER JOIN aisle_info ON tag_logs.reader_ID = aisle_info.reader_ID 
    AND customer_info 
INNER JOIN current_tags ON customer_info.name = customer_info.name 
WHERE tag_logs.tag_no = 3222813112261