2017-04-20 21 views
1

在準備好的聲明中,我必須從'通知玩家'表中獲取僅限於當前日期的'入'的玩家數'在MySQL中。我用 'CURDATE()/ CURRENT_DATE()' 查詢功能,而且計數始終返回 '0'如何在'當前日期'狀態中獲得某個列的計數

查詢:

select count(1) as count 
from notifyplayers 
where lower(availability) = 'in' and notifydate = curdate(); 

請找到表屏幕截圖:

enter image description here

有人可以幫忙找出查詢中的問題。

回答

1

你的約會時間分量,所以一個方法是:

select count(1) as count 
rom notifyplayers 
where lower(availability) = 'in' and 
     date(notifydate) = curdate(); 

不過,我會建議:

select count(1) as count 
rom notifyplayers 
where lower(availability) = 'in' and 
     notifydate >= curdate() and 
     notifydate < curdate() + interval 1 day; 
+0

我已經使用了第一查詢和它工作正常。但是第二個查詢失敗,拋出錯誤:0 14:21:17 \t select count(1)as countplay from notifyplayers where lower(availability)='in'and notifydate> = curdate()and notifydate soccerway

0

試試這個:

select count(1) from notifyplayers 
where lower(availability) = 'in' and date(notifydate) = date(curdate()); 
+1

純代碼答案在教育SO讀者方面做得很少。您的答案可能是也可能不是正確的答案,但它在被標記爲「低質量」之後處於審覈隊列中。請花一點時間來解釋一下以改善您的答案。 – mickmackusa

相關問題