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`子句,在我尝试时返回错误。