--该时间段的上一条记录
select   ID,UserID,UserName,DateTime,OperatorType,Score,Mark,CpsId from t_user_scoredetails where userid=11 and DateTime<'2013-01 00:00:00' order by DateTime desc LIMIT 1 
UNION  
--时间段的记录
select ID,UserID,UserName,DateTime,OperatorType,Score,Mark,CpsId from t_user_scoredetails  where userid=11 and DateTime BETWEEN '2013-01 00:00:00' AND '2013-02 00:00:00'二条语句独立时可以执行,加上Union就报错,不明白为什么,请指点,谢谢

解决方案 »

  1.   

    报什么错误??
    (select ID,UserID,UserName,DateTime,OperatorType,Score,Mark,CpsId from t_user_scoredetails where userid=11 and DateTime<'2013-01 00:00:00' order by DateTime desc LIMIT 1)
    UNION  
    (select ID,UserID,UserName,DateTime,OperatorType,Score,Mark,CpsId from t_user_scoredetails  where userid=11 and DateTime BETWEEN '2013-01 00:00:00' AND '2013-02 00:00:00')
    加上括号试试
      

  2.   

    ,确实加上括号就可以了,谢谢,用惯了SQLServer,看来还真有些区别的