【无标题】SQL+HIVE 题目:查询接下来5天要过生日的学生

SELECT * FROM (
SELECT birthday , month(current_date()    )   nowmonth    ,month(date_add(current_date(),5)) nextmonth ,month(to_date(birthday))  usermonth , day(current_date()    )   nowday    ,day(date_add(current_date(),5)) nextday         
,  day(to_date(birthday))   userday    from tablename
)

WHERE 
(
nowmonth  != nextmonth AND
(
  (nowmonth==  usermonth AND userday>  nowday   )
  or (nextmonth ==  usermonth AND  userday <= nextday  ) 
)
)
OR  (nowmonth  == nextmonth   AND   userday   >  nowday  AND  userday <=nextday )
;

你可能感兴趣的:(java,ORACLE,sql,hive,数据库)