Mysql

查詢不斷給我“未知列”問題

  • July 18, 2018

在過去的幾天裡,我對我遇到的這個錯誤進行了很多研究,但我無法真正修復它,所以我希望有人能幫助我。查詢不斷告訴我:

ERROR 1054 (42S22): Unknown column 'updated_at' in 'field list'

這是查詢:

SELECT  TIME_TO_SEC(SUM(TIMEDIFF(updated_at, created_at))) AS total FROM
       ( SELECT  DISTINCT date(l.created_at), 
               ( SELECT  MIN(created_at)
                   FROM  logs
                   WHERE  updated_at BETWEEN l.created_at AND l.updated_at
               ) AS TIME_ENTER,
               ( SELECT  MAX(updated_at)
                   FROM  logs
                   WHERE  created_at BETWEEN l.created_at AND l.updated_at
               ) AS TIME_EXIT
           FROM  logs l
       ) AS whatever
   WHERE  updated_at <> CONVERT(updated_at USING ASCII)
   GROUP BY  date(created_at);

我的桌子的描述是:

+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| job_id      | int(10) unsigned | NO   | MUL | NULL    |                |
| timecard_id | int(10) unsigned | NO   | MUL | NULL    |                |
| event_id    | int(10) unsigned | NO   | MUL | NULL    |                |
| duration    | int(11)          | YES  |     | NULL    |                |
| gap         | int(11)          | NO   |     | 0       |                |
| created_at  | timestamp        | YES  |     | NULL    |                |
| updated_at  | timestamp        | YES  |     | NULL    |                |
+-------------+------------------+------+-----+---------+----------------+

我嘗試尋找不可列印的字元,但沒有成功

任何幫助將不勝感激,在此先感謝!

問題是你selectfrom部分:

SELECT DISTINCT date(l.created_at),
(SELECT MIN(created_at) FROM logs WHERE updated_at BETWEEN l.created_at AND l.updated_at) AS TIME_ENTER,
(SELECT MAX(updated_at) FROM logs WHERE created_at BETWEEN l.created_at AND l.updated_at) AS TIME_EXIT
FROM logs l

不返回欄位updated_at

引用自:https://dba.stackexchange.com/questions/212427