DATEDIFF中的SELECT无法正常工作

时间:2013-09-25 09:40:31

标签: mysql

SELECT DATEDIFF(day,(SELECT creation_date
   FROM time_info
   WHERE is_on = 'yes'
   LIMIT 0,1),
   (SELECT creation_date
    FROM time_info
    WHERE is_on = 'no'
    LIMIT 0,1)
FROM time_info;

我想计算日期差异,但事情并非如此。还有另一种方法吗?

3 个答案:

答案 0 :(得分:0)

你的牙套'(',')'在SELECT语句中不平衡。

答案 1 :(得分:0)

试试这个

   SELECT DATEDIFF(t1.creation_date,t2.creation_date )
   FROM time_info t1
   INNER JOIN time_info t2 ON t1.your_id_column = t2.your_id_column
   WHERE t1.is_on = 'yes'  AND t2.is_on = 'no';

答案 2 :(得分:0)

试试这个

set @date1:=(SELECT creation_date
   FROM time_info
   WHERE is_on = 'yes'
   LIMIT 0,1);

set @date2:=   (SELECT creation_date
    FROM time_info
    WHERE is_on = 'no'
    LIMIT 0,1);
select datediff(@date1,@date2);

您需要提供更多信息才能了解您的目标