2014-03-07 43 views
0

是否有任何理由爲什麼MySQL不喜歡我的where子句中的下列顯式引用。MySQL明確引用table.column在哪裏條款

where [table]。[column]?

我得到一個錯誤查詢無效:未知列在「plugin_thold_log.id「where子句」

這部作品在TSQL。

'plugin_thold_log是我的數據庫中的一個表,id顯然是同一個表中的一列。

我的全部查詢:

這裏是我完整的查詢:

select pl.id as id, 
from_unixtime(pl.time) as time, 
case 
when TIMESTAMPDIFF(MINUTE,(select from_unixtime(a.time) from plugin_thold_log a where a.id < plugin_thold_log.id and a.time >= '$dateStart' and a.time <= '$dateEnd' order by a.id desc LIMIT 1),from_unixtime(pl.time)) is null then 1 
when TIMESTAMPDIFF(MINUTE,(select from_unixtime(a.time) from plugin_thold_log a where a.id < plugin_thold_log.id and a.time >= '$dateStart' and a.time <= '$dateEnd' order by a.id desc LIMIT 1),from_unixtime(pl.time)) > 30 then 1 
when TIMESTAMPDIFF(MINUTE,(select from_unixtime(a.time) from plugin_thold_log a where a.id < plugin_thold_log.id and a.time >= '$dateStart' and a.time <= '$dateEnd' order by a.id desc LIMIT 1),from_unixtime(pl.time)) < 30 
    and TIMESTAMPDIFF(MINUTE,(select from_unixtime(a.time) from (select from_unixtime(a.time) from plugin_thold_log a where a.id < plugin_thold_log.id and a.time >= '$dateStart' and a.time <= '$datEend' order by a.id desc LIMIT 7) a order by 1 asc LIMIT 1),from_unixtime(pl.time)) < 30 then 0 
when TIMESTAMPDIFF(MINUTE,(select from_unixtime(a.time) from plugin_thold_log a where a.id < plugin_thold_log.id and a.time >= '$dateStart' and a.time <= '$dateEnd' order by a.id desc LIMIT 1),from_unixtime(pl.time)) < 30 
    and TIMESTAMPDIFF(MINUTE,(select from_unixtime(a.time) from (select from_unixtime(a.time) from plugin_thold_log a where a.id < plugin_thold_log.id and a.time >= '$dateStart' and a.time <= '$datEend' order by a.id desc LIMIT 7) a order by 1 asc LIMIT 1),from_unixtime(pl.time)) is null then 0 
else 1 
end 
from 
plugin_thold_log pl 

where 
pl.time >= '$dateStart' 
and pl.time <= '$dateEnd' 
order by 1 

回答

0

我不能重現該問題,測試代碼按預期工作:

/*Table structure for table `plugin_thold_log` */ 

DROP TABLE IF EXISTS `plugin_thold_log`; 

CREATE TABLE `plugin_thold_log` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, 
    PRIMARY KEY (`id`) 
) ENGINE=INNODB; 

/*Data for the table `plugin_thold_log` */ 

INSERT INTO `plugin_thold_log`(`id`) VALUES (NULL); 

SELECT `id` 
FROM `plugin_thold_log` 
WHERE `plugin_thold_log`.`id` = 1; 

SQL Fiddle demo

UPDATE

/* 
Error Code : 1054 
Unknown column 'plugin_thold_log.id' in 'where clause' 

SELECT 
    ( SELECT `id` 
     FROM `plugin_thold_log` `a` 
     WHERE `a`.`id` != `plugin_thold_log`.`id` 
    ) 
FROM `plugin_thold_log` `pl`; 
*/ 

變化:

SELECT 
    ( SELECT `id` 
     FROM `plugin_thold_log` `a` 
     WHERE `a`.`id` != `pl`.`id` 
    ) 
FROM `plugin_thold_log` `pl`; 
+0

加了我完整的查詢 –

+0

@AndrewBurns:回答更新,你可能會有幫助。 – wchiquito

+0

謝謝wchiquito仍然得到相同的未知列錯誤:( –