[英]query with INNER JOIN
The tables are created and have some data inserted I am trying to get the route
from the arrivaltimes
table with the aid of JOIN INNER but I am getting nothing back I have already tried to adjust the time to the current time tin th arrivaltimes table but the result is always empty. 这些表已创建并插入了一些数据,我试图借助JOIN INNER来从到达
arrivaltimes
获取route
,但是我什么也没回来,我已经尝试将时间调整为当前时间到达时间表,但是结果始终为空。 I am not getting any error. 我没有任何错误。 Is something wrong with my query?
我的查询有问题吗?
CREATE TABLE IF NOT EXISTS stops
(stop_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(30) NOT NULL,
lat double(10,6) NOT NULL,
longi double(10,6)NOT NULL)
CREATE TABLE IF NOT EXISTS arrivaltimes
(arrivaltimes_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
weekday VARCHAR(20) NOT NULL,
route INT(11) NOT NULL,
arrivaltime time NOT NULL,
stop_id INT, FOREIGN KEY fk_stop_id(stop_id) REFERENCES stops(stop_id) )
SELECT route from arrivaltimes INNER JOIN stops ON arrivaltimes.stop_id=stops.stop_id where arrivaltime = now()
arrivaltime
is having datatype time
and its in the format H:i:s
. arrivaltime
time
数据类型为time
,其格式为H:i:s
。
In the where clause you are using now()
and it will be in the format Ymd H:i:s
在where子句中,您使用
now()
,其格式为Ymd H:i:s
You need to use curtime
function for that. 您需要为此使用
curtime
函数。
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2015-05-10 23:46:44 |
+---------------------+
1 row in set (0.00 sec)
mysql> select curtime();
+-----------+
| curtime() |
+-----------+
| 23:46:53 |
+-----------+
1 row in set (0.00 sec)
where arrivaltime = curtime()
your query is perfectly fine the problem is only with the time you provide as input. 您的查询非常好,问题只在于您提供的输入时间。
The format of TIME data type is 'HH:MM:SS' so use time(now()) this will give you proper results. TIME数据类型的格式为'HH:MM:SS',因此使用time(now())可以给您适当的结果。
mysql> select time(now()); mysql>选择时间(now());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.