[英]Get Current Month
這是我的數據庫示例:
狀態日期
問2012-08-02。
在這里,如果我運行我的應用程序,則意味着我希望顯示2。這是以下信息。 -在顯示總共獲得了多少條匹配的信息后,檢查數據庫當前月+狀態= Q ,例如,總計2表示顯示輸出2。
已經我做獲得當前日期+狀態總計數值= Q information.it成功完成。 在這里,我使用此代碼:
public class RetailerWs {
public int data(){
int count=0;
//count++;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager
.getConnection("jdbc:mysql://localhost:3306/pro","root","");
PreparedStatement statement = con
.prepareStatement("select * from orders where status='Q' AND date=CURDATE()");
ResultSet result = statement.executeQuery();
while(result.next()) {
// Do something with the row returned.
count++; //if the first col is a count.
}
}
catch (Exception exc) {
System.out.println(exc.getMessage());
}
return count;
}
}
另一類是:
public class Demo {
public static void main(String[] args){
RetailerWs obj = new RetailerWs();
System.out.println(obj.data());
}
}
上面的代碼用於獲取當前日期+ status = Q的信息 。 請幫助我如何編寫當前月份的代碼+ status = Q ....
它應該是:
select * from orders where status='Q' AND MONTH(date) = MONTH(CURDATE())
有關MySQL的日期和時間功能的更多信息,請參見THIS 。
本周,請嘗試:
select * from orders where status='Q' AND WEEK(date) = WEEK(CURDATE())
對於今年的一周內,嘗試:
select * from orders where status='Q' AND WEEK(date) = WEEK(CURDATE()) AND YEAR(date) = YEAR(CURDATE())
要一次檢查所有內容,請使用:
select * from orders where status='Q' AND YEARWEEK(date) = YEARWEEK(CURDATE())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.