简体   繁体   English

错误代码:1052。where子句中的列“ datetime”不明确

[英]Error Code: 1052. Column 'datetime' in where clause is ambiguous

I have 15 tables of same column names and want to retrieve data on datetime condition but struggling to find out how to do this. 我有15个具有相同列名的表,并且想在datetime条件下检索数据,但仍在努力寻找方法。

select * FROM AlbertstreetIN1,
AlbertstreetIN2,
AlbertstreetOUT1,
AshtonRPIN1,
AshtonRPIN2
WHERE datetime BETWEEN "2014-08-31 00:00:00" AND "2014-08-31 23:59:59";

data time is ambiguous for all the table names- error. 所有表名的数据时间都不明确-错误。

table format-- id,camera_id,name,plate,datetime, nationlilty,image_name,image. 表格格式-id,camera_id,名称,标牌,日期时间,国家,图像名称,图像。

If a column is ambiguous than it means more than one table in your query has a column with that name. 如果一列不明确,则意味着查询中的多个表都有该名称的列。

So you have to tell the DB which column you mean by adding the table name. 因此,您必须通过添加表名称来告诉数据库您要指的是哪一列。

WHERE AlbertstreetIN1.datetime BETWEEN '2014-08-31 00:00:00' 
                                   AND '2014-08-31 23:59:59'

Don't know which table you want in your condition. 不知道您要哪种状态的表。 I just chose one. 我只是选了一个。

And you did not specify how to join your tables. 而且您没有指定如何联接表。 They have to be linked somehow and you need to specify that in your query. 它们必须以某种方式链接,并且您需要在查询中指定。

Otherwise you need to union them like this 否则,你需要union他们这样

select * FROM AlbertstreetIN1 WHERE datetime BETWEEN '2014-08-31 00:00:00' 
                                   AND '2014-08-31 23:59:59'
UNION ALL
select * FROM AlbertstreetIN2 WHERE datetime BETWEEN '2014-08-31 00:00:00' 
                                   AND '2014-08-31 23:59:59'
UNION ALL
select * FROM AlbertstreetOUT1 WHERE datetime BETWEEN '2014-08-31 00:00:00' 
                                   AND '2014-08-31 23:59:59'
UNION ALL
select * FROM AshtonRPIN1 WHERE datetime BETWEEN '2014-08-31 00:00:00' 
                                   AND '2014-08-31 23:59:59'
UNION ALL
select * FROM AshtonRPIN2WHERE datetime BETWEEN '2014-08-31 00:00:00' 
                                   AND '2014-08-31 23:59:59'

Use table name or alias name in where condition. 在where条件中使用表名或别名。 Since datetime is present in more than one tables you can not use it in WHERE condition without table name or its alias. 由于datetime存在于多个表中,因此如果没有表名或其别名,则无法在WHERE条件下使用它。

like AlbertstreetIN1.datetime . 就像AlbertstreetIN1.datetime一样。

Can you try like this? 你可以这样尝试吗?

datetime is a one of keyword / predefined in MYSQL datetime是MYSQL中关键字/预定义的关键字之一

WHERE datetime BETWEEN "2014-08-31 00:00:00" AND "2014-08-31 23:59:59";

to

WHERE `datetime` BETWEEN "2014-08-31 00:00:00" AND "2014-08-31 23:59:59";

or smething like this 或像这样的东西

WHERE (AlbertstreetIN1.datetime BETWEEN "2014-08-31 00:00:00" AND "2014-08-31 23:59:59") || (AlbertstreetIN2.datetime BETWEEN "2014-08-31 00:00:00" AND "2014-08-31 23:59:59");

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

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