MySql根据时间决定查询条件

select * from

(

select dps3_pt_nbr, dps3_batch_no, dps3_plan_date,

dps3_vend, dps3_qty, dps3_po_nbr, create_ts,

dps3_type, dps3_year, dps3_week, dps3_expired, dps3_parent_id,

dps3_line_type, dps3_char01, dps3_char02

from srm_dps3

where dps3_type = '3' and dps3_expired='NEW' 

and dps3_pt_nbr in (select pt_part from srm_pt_mstr where pt_group='BC' /*and pt_classify='J'*/ )

and

case when hour(now())<=12 then

  (dps3_plan_date >= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 DAY),'%Y-%m-%d') AND dps3_plan_date <= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL -1 DAY),'%Y-%m-%d'))

else

(dps3_plan_date >= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 0 DAY),'%Y-%m-%d') AND dps3_plan_date <= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL -1 DAY),'%Y-%m-%d'))

end

) as plan left join

(

select pods_pt_part,(select distinct pos_vend from srm_po_send_mstr where pos_nbr = pods_nbr) as vdx,

(select pod_req_nbr from srm_po_det where pods_podid = pod_id) as reqnbrx,

sum(ifnull(pods_send_qty,0)) as sendx,sum(ifnull(pods_loc_qty,0)) as locx,

sum(ifnull(pods_qty,0)) qcokx,sum(ifnull(pods_qty_rt,0)) as rtx

from srm_po_send_det

where

case when hour(now())<=12 then

  (create_ts >= CONCAT(DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 DAY),'%Y-%m-%d'),' 12:50:00')

AND create_ts <= CONCAT(DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 0 DAY),'%Y-%m-%d'),' 12:50:00')

)

else

create_ts >= CONCAT(DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 0 DAY),'%Y-%m-%d'),' 12:50:00')

end

group by pods_pt_part,vdx,reqnbrx 

) as send

on plan.dps3_pt_nbr = send.pods_pt_part

and plan.dps3_vend = send.vdx

and plan.dps3_batch_no = send.reqnbrx

你可能感兴趣的:(MySql根据时间决定查询条件)