[英]How to get all category with their sum of products using their attribute in mysql
[英]how can i get the sum of all the products in a certain month in mysql
我正在嘗試獲取特定月份的所有付款總額,可以說從1月到3月在我的網站上。 我的設備表具有Money和Joined作為列,但是Joined列同時具有日期和時間。 如果可能的話,我想使用這種方法,但是此代碼段僅供參考。
if(isset($ _ POST ['moneyMade'])){$ moneyMade = 0;
$query = "select SUM(Money) from users where Joined<='2016-11-01 00:00:00' and Joined>='2016-11-31 00:00:00'";
//if (!$query) { echo 'MySQL Error: ' . mysqli_error(); exit; }
//$query="select * from equipments ";
$result = mysqli_query($conn,$query);
while ($row = mysqli_fetch_assoc($result)){ /* Fetch a result row as an associative array */
/*while ($row = mysqli_result($result)){*/
$moneyMade +=$row['Money'];
}
echo "Money made for this month is ". $moneyMade;
}
我如何使用php和一些sql實現此目的? 謝謝。
假設Prize
是一個數值,您可以執行以下操作。
$month = 'January';
$month_start = strtotime("first day of {$month}");
$month_end = strtotime("last day of {$month}");
$query = "SELECT SUM(`Prize`) FROM `equipments` WHERE UNIX_TIMESTAMP(`Joined`) >= {$month_start} AND UNIX_TIMESTAMP(`Joined`) <= {$month_end}";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.