感謝爲最大時間比較, 我已經對語法做了更改
SELECT count(*) FROM fax
WHERE ((date = CURDATE() and (time >='22:00' and time <= '23:59'))
or (date=CURDATE() + INTERVAL 1 DAY and (time >= '00:00' and time <= '7:00')))
and shift = 'GY'
and complete = 1
現在我的問題是移位的範圍是今天晚上10點到湯姆7am。
但是,當更改日期
HELP在使用我的語法上面仍然得到錯誤的if語句MYSQL
IF YES(選擇此)ELSE IF(選擇此) 如何正確IF ELSE在使用MYSQL語句
SELECT count(*) FROM fax
IF
(date = CURDATE() and (time >='22:00' and time <= '23:59')
THEN
SELECT count(*) FROM fax
WHERE ((date = CURDATE() and (time >='22:00' and time <= '23:59'))
or (date=CURDATE() + INTERVAL 1 DAY and (time >= '00:00' and time <= '7:00')))
and shift = 'GY' and complete = 1
ELSE IF
(date = CURDATE() and (time >= '00:00' and time <= '7:00')
THEN
SELECT count(*) FROM fax
WHERE ((date = CURDATE() and (time >= '00:00' and time <= '7:00'))
or (date=CURDATE() - INTERVAL 1 DAY and (time >='22:00' and time <= '23:59')))
and shift = 'GY' and complete = 1
你從db中獲得計數的方式是錯誤的。你應該選擇計數,而不是記錄來計算它們。 –
謝謝你。這是一個壞習慣。你可以檢查我的答案下面我在這個聲明中有另一個問題 – Newbie