[英]How to get the weekly, monthly and yearly sales using where statements
Hi i already get the daily sales.嗨,我已经获得了每日销售额。 now i want to get the weekly, monthly and yearly sales and already tried the weekly sales but the problem is the monthly sales is the one being selected
现在我想获得每周、每月和每年的销售额,并且已经尝试过每周销售额,但问题是每月销售额是被选中的那个
public void weekly(){
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM/dd/yyyy");
LocalDateTime now = LocalDateTime.now();
String date = dtf.format(now);
try{
con = Connector.getConnection();
java.sql.Statement st = con.createStatement();
String query = "SELECT sum(Quantity) FROM `salesproduct_table` WHERE Date = WEEK(CURDATE())";
ResultSet rs = st.executeQuery(query);
if(rs.next()){
productsales4.setText(rs.getString(1));
}
}catch(Exception ex){
}
tried already different kind of syntax but i cant fix it已经尝试过不同类型的语法,但我无法修复它
For month:对于一个月:
String query = "SELECT sum(Quantity) FROM `salesproduct_table` WHERE MONTH(Date) = MONTH(CURDATE())";
for year:年:
String query = "SELECT sum(Quantity) FROM `salesproduct_table` WHERE YEAR(Date) = YEAR(CURDATE())";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.