#1054 - 未知列' val'在' on条款'选择MIN()时

时间:2014-03-31 23:00:20

标签: mysql

SELECT IF(TIME_TO_SEC(TIMEDIFF(t1.dal, NOW())) < 0,
          -TIME_TO_SEC(TIMEDIFF(t1.dal, NOW())),
          NULL
       ) AS val, t2.*
FROM test t1
JOIN 
  (SELECT prod, MIN(
                    IF(TIME_TO_SEC(TIMEDIFF(dal, NOW())) < 0,
                       -TIME_TO_SEC(TIMEDIFF(dal, NOW())),
                       NULL
                    )
                 ) AS minVal
   FROM test
   GROUP BY prod
  ) t2
ON val = minVal
AND t1.prodotto = t2.prodotto;

此查询返回#1054 - 未知列&#39; val&#39;在条款&#39;。

我想要做的是选择MIN()作为描述,但也选择相应的id

我想获得与this问题相同的结果,但不是简单地选择MIN(Value) minVal然后与ON t.Value = t2.minVal AND t.prod = t2.prod进行比较,我添加操作MIN(IF(TIME ... )so I have no idea how to compare then on the ON`子句,在我尝试时返回错误。

0 个答案:

没有答案