0
我有這個查詢,並且我試圖在我的where子句中使用用戶定義的變量@noVar來只顯示那個變量的值爲'是'的記錄。 但是當我在下面的查詢中使用Having @noVar ='Yes'時,它返回0結果。如何在where子句中使用用戶定義的變量
SELECT svcreqdetail.id, svcreqcheckin.stime as checkin, @etime:= time(timestampadd(minute, svcreqdetail.hours*60 , concat(caredate,' ', caretime))) as endtime, svcreqcheckout.stime as checkout, time_to_sec(if(svcreqcheckout.stime > svcreqcheckin.stime,
timediff(svcreqcheckout.stime, svcreqcheckin.stime),
addtime(timediff(svcreqcheckout.stime, svcreqcheckin.stime), '24:00:00.000000')))/3600 AS wrkHrs, svcreqdetail.hours,
svcreqstatus.status, @checkoutvar:= time_to_sec(timediff(svcreqcheckout.stime, @etime))/60 as checkoutvar,@noVar:= if (@checkoutvar <= 15,'Yes', 'No') as noVar, qualif
FROM svcreqdetail
LEFT JOIN svcreqcheckin ON svcreqcheckin.reqid = svcreqdetail.id
LEFT JOIN svcreqcheckout ON svcreqcheckout.reqid = svcreqdetail.id
JOIN svcreqstatus ON svcreqstatus.reqdid = svcreqdetail.id
WHERE (yearweek(caredate) = yearweek(date_sub(CURRENT_DATE, INTERVAL 1 week))
AND svcreqstatus.status != 'Incompleted'
AND svcreqstatus.status != 'Deleted')
having @noVar = 'Yes'
是否有無論如何我可以在我的where子句中測試該變量。並感謝你
哪裏是用戶定義的變量來自?通常你使用了一個參數化的查詢/準備語句。你能否提供使用的語言信息?或者這只是一個存儲過程? – Jpsh
它是用select子句定義的,我將使用php,但是@noVar變量必須在查詢中計算,因爲我從其他列的計算中定義它 – LaliNonda