sql的union操作

select a.*,sysdate-b.op_date time_dif from whms_detail a,

(

select whms_material_detail_id,max(in_date) op_date from

(

select  w1.whms_material_detail_id, w1.in_date from iitdb.whms_ in w1 where w1.valid_flag =1

union

select  w2.whms_material_detail_id, w2.out_date from iitdb.whms_ out w2 where w2.valid_flag =1

)

group by whms_detail_id

having sysdate-max(in_date)>30 )  b

where a.whms _detail_id = b.whm _detail_id

and a.valid_flag = 1

 

// 这里的sysdate是系统时间

你可能感兴趣的:(数据库查询(sql)