简体   繁体   English

字段列表中的“条形码”列不明确

[英]column 'barcode' in field list is ambiguous

SELECT barcode, t3.employee,
SEC_TO_TIME(SUM(TIMESTAMPDIFF(SECOND, dateandtime, (SELECT IFNULL(MIN(dateandtime),NOW())
                                                  FROM wwtlog b
                                                 WHERE b.barcode = a.barcode
                                                   AND b.dateandtime  > a.dateandtime
                                                   AND b.inorout = 'IN'
                                                )))) timeused
FROM wwtlog a
    JOIN (SELECT t1.barcode, t1.employee FROM wwtlog t1
  JOIN (SELECT barcode, MAX(id) id FROM wwtlog GROUP BY barcode) t2
ON t1.id = t2.id AND t1.barcode = t2.barcode) t3 ON t1.barcode = barcode
WHERE inorout = 'OUT' and barcode IN (SELECT t1.barcode FROM wwtlog t1
                                JOIN (SELECT barcode, MAX(dateandtime) dateandtime FROM wwtlog GROUP BY barcode) t2
                                ON t1.barcode = t2.barcode AND t1.dateandtime = t2.dateandtime WHERE inorout = 'IN')
GROUP BY barcode;

Any help on this would be fantastic, I started getting this when I added the join in to get t3.employee. 任何有关这方面的帮助都很棒,当我添加加入来获取t3.employee时,我开始得到这个。 I have a feeling that I don't know what I'm doing. 我有一种感觉,我不知道自己在做什么。

Im trying to get Unique Barcode, with the total time between time IN and time OUT time stamps. 我试图获得唯一条形码,时间IN和时间OUT时间戳之间的总时间。 I was trying to use the join to get the employee that last had the item(barcode) checked out or in. if you take out the join for t3.employee, and just ask for employee, it gives me the first record employee for each barcode, not the last one. 我试图使用联接来获得最后一个项目(条形码)签出或签入的员工。如果你拿出t3.employee的加入,并且只是要求员工,它给了我第一个记录员工条形码,而不是最后一个。

You are using the column barcode but this column is present in several table try assign the table alias ar each barcode column 您正在使用列条形码,但此列存在于多个表中,请尝试为每个条形码列分配表别名

SELECT a.barcode, t3.employee,
SEC_TO_TIME(SUM(TIMESTAMPDIFF(SECOND, dateandtime, (SELECT IFNULL(MIN(dateandtime),NOW())
                                                  FROM wwtlog b
                                                 WHERE b.barcode = a.barcode
                                                   AND b.dateandtime  > a.dateandtime
                                                   AND b.inorout = 'IN'
                                                )))) timeused
FROM wwtlog a
    JOIN (SELECT t1.barcode, t1.employee FROM wwtlog t1
  JOIN (SELECT barcode, MAX(id) id FROM wwtlog GROUP BY barcode) t2
ON t1.id = t2.id AND t1.barcode = t2.barcode) t3 ON t1.barcode = a.barcode
WHERE inorout = 'OUT' and a.barcode IN (SELECT t1.barcode FROM wwtlog t1
                                JOIN (SELECT barcode, MAX(dateandtime) dateandtime FROM wwtlog GROUP BY barcode) t2
                                ON t1.barcode = t2.barcode AND t1.dateandtime = t2.dateandtime WHERE inorout = 'IN')
GROUP BY a.barcode;

expecially at the main table eg: wwtlog a 特别是在主桌上,例如:wwtlog a

You're missing a table reference at ON t1.barcode = barcode. 您在ON t1.barcode =条形码时缺少表格引用。 Since barcode column is in multiple tables it needs to be strictly identified so as not to be ambiguous. 由于条形码列在多个表中,因此需要严格识别,以免模糊不清。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM