SQL中的分组和总结

发布于 2025-02-09 14:49:29 字数 560 浏览 4 评论 0原文

美好的一天,

我想找出如何通过对帐户进行分组并总结帐户每月的孙子来对以下数据进行分类和分组。

这是我当前的选择语句:

SELECT 
    tbl_AccountLedger.ledgerName
    ,tbl_SalesMaster.date
    , tbl_SalesMaster.grandTotal

  FROM tbl_SalesMaster
  INNER JOIN tbl_AccountLedger ON tbl_SalesMaster.ledgerId =tbl_AccountLedger.ledgerId
 

这是WAT我的选择语句带回

”在此处输入图像说明

现在,我需要通过将每个月的grand总计用于legerName来对这些数据进行排序

Good day

I would like to find out how I would Sort and group the following data by grouping the Account and summing the grandTotal of the Account per Month.

This is my current Select statement:

SELECT 
    tbl_AccountLedger.ledgerName
    ,tbl_SalesMaster.date
    , tbl_SalesMaster.grandTotal

  FROM tbl_SalesMaster
  INNER JOIN tbl_AccountLedger ON tbl_SalesMaster.ledgerId =tbl_AccountLedger.ledgerId
 

Here is wat my select statement is bringing back

enter image description here

Now I need to sort this data by summing the grand total for each month for a legerName

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有你我更好 2025-02-16 14:49:29

您可以在SQL 2012或更高版本上使用以下查询。我建议请阅读SQL中的分组。

SELECT 
tbl_AccountLedger.ledgerName
,DATEFROMPARTS(YEAR(tbl_SalesMaster.date),MONTH(tbl_SalesMaster.date),1) AS Month
, SUM(tbl_SalesMaster.grandTotal) AS TotalGrandTotal
FROM tbl_SalesMaster
  INNER JOIN tbl_AccountLedger ON tbl_SalesMaster.ledgerId =tbl_AccountLedger.ledgerId
GROUP BY tbl_AccountLedger.ledgerName, DATEFROMPARTS(YEAR(tbl_SalesMaster.date),MONTH(tbl_SalesMaster.date),1)

You can use the below query on SQL 2012 or higher version. I will suggest please read grouping in SQL.

SELECT 
tbl_AccountLedger.ledgerName
,DATEFROMPARTS(YEAR(tbl_SalesMaster.date),MONTH(tbl_SalesMaster.date),1) AS Month
, SUM(tbl_SalesMaster.grandTotal) AS TotalGrandTotal
FROM tbl_SalesMaster
  INNER JOIN tbl_AccountLedger ON tbl_SalesMaster.ledgerId =tbl_AccountLedger.ledgerId
GROUP BY tbl_AccountLedger.ledgerName, DATEFROMPARTS(YEAR(tbl_SalesMaster.date),MONTH(tbl_SalesMaster.date),1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文