错误代码:1052. where 子句中的列“datetime"不明确 [英] Error Code: 1052. Column 'datetime' in where clause is ambiguous

查看:31
本文介绍了错误代码:1052. where 子句中的列“datetime"不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 15 个具有相同列名的表,我想在日期时间条件下检索数据,但正在努力找出如何执行此操作.

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.

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.

表格格式--id,camera_id,name,plate,datetime,nationallilty,image_name,image.

table format-- id,camera_id,name,plate,datetime, nationlilty,image_name,image.

推荐答案

如果一列不明确,则意味着您的查询中有多个表具有该名称的列.

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.

否则你需要像这样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'

这篇关于错误代码:1052. where 子句中的列“datetime"不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆