简体   繁体   English

每月如何获得总计?

[英]How can I get the Total every month?

I'm doing the dashboard for our system. 我正在为我们的系统做仪表板。 I want to add a bar graph which displays the total transaction every month from January to December this year. 我想添加一个条形图,以显示今年1月至12月每个月的总交易额。 Can somebody help me with my problem? 有人可以帮我解决我的问题吗? This is my query. 这是我的查询。

  SELECT tbl_barangay.barangay_name, 
   tbl_transaction_details.supplier_medicine_id, 
   tbl_supplier_medicine.medicine_name, 
   SUM(tbl_transaction_details.total_price) as 'Total' 
  FROM 
   tbl_transaction_details 
  INNER JOIN 
   tbl_supplier_medicine ON tbl_transaction_details.supplier_medicine_id = 
   tbl_supplier_medicine.supplier_medicine_id 
  INNER JOIN 
   tbl_transaction ON tbl_transaction.transaction_id = 
   tbl_transaction_details.transaction_id
  INNER JOIN 
   tbl_barangay ON tbl_barangay.barangay_id = tbl_transaction.barangay_id 
  WHERE 
   tbl_barangay.barangay_id = 1 
  AND 
   tbl_transaction.transaction_date BETWEEN "2019-08-18" AND "2019-08-18"
  GROUP BY
   tbl_transaction_details.supplier_medicine_id

I don't know your database schema well but can you please look into this line? 我不太了解您的数据库架构,但是可以请您调查一下这行吗?

tbl_transaction.transaction_date BETWEEN "2019-08-18" AND "2019-08-18"

I think this is one of the reasons that are causing problems because the transaction date is not selecting the whole year dates. 我认为这是引起问题的原因之一,因为交易日期未选择全年日期。

Also, the GROUP BY clause should contain all columns except the aggregation columns. 另外, GROUP BY子句应包含除聚合列以外的所有列。 So, the GROUP BY clause should be like this, 因此, GROUP BY子句应该像这样,

GROUP BY
   tbl_barangay.barangay_name, 
   tbl_transaction_details.supplier_medicine_id, 
   tbl_supplier_medicine.medicine_name

Hope, this helps. 希望这可以帮助。 Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM