-1

我正在尝试按月汇总我的每日数据 (trunc(DM_OWNER.LD_LEG_DW.CPLD_DTT)。这是在 Web Intelligence BI 报告中创建的。

SELECT
  DM_OWNER.LD_LEG_DW.LGST_GRP_CD,
  DM_OWNER.LGST_GRP_T.LGSTGRP_DESC,
  DM_OWNER.LD_LEG_DW.CARR_CD,
  DM_OWNER.LD_LEG_DW.LD_LEG_ID,
  DM_OWNER.LD_LEG_DW.BILL_TO_CUST_CD,
  trunc(DM_OWNER.LD_LEG_DW.CPLD_DTT),
  trunc(DM_OWNER.VCHR_AP_T.CRTD_DTT),
  AP_Detail.PYMNT_AMT_DLR
FROM
  DM_OWNER.LD_LEG_DW,
  DM_OWNER.LGST_GRP_T,
  DM_OWNER.VCHR_AP_T,
  DM_OWNER.CHRG_DETL_T_NOTOTAL_V  AP_Detail
WHERE
  ( DM_OWNER.LD_LEG_DW.LD_LEG_ID=DM_OWNER.VCHR_AP_T.LD_LEG_ID(+)  )
  AND  ( DM_OWNER.VCHR_AP_T.VCHR_NUM=AP_Detail.VCHR_NUM_AP  )
  AND  ( DM_OWNER.LD_LEG_DW.LGST_GRP_CD=DM_OWNER.LGST_GRP_T.LGST_GRP_CD  )
  AND  
  (
   DM_OWNER.LD_LEG_DW.LGST_GRP_CD  In  ( 'PBRK'  )
   AND
   trunc(DM_OWNER.VCHR_AP_T.CRTD_DTT)  >=  '01-10-2012 00:00:00'
  )
4

2 回答 2

2

没有明确的字段名称,或者对数据结构的解释,这太模糊了。但原理是

select 
     displayfields,
     year(datefield), month(datefield), 
     sum(valuefield)
from yourtable
group by 
     displayfields,
     year(datefield), month(datefield), 
于 2012-10-16T13:40:57.560 回答
0

在不涉及查询的细节的情况下,这是一种通用方法。

CAST 很讨厌,但这样做的好处是给你一个实际的 DATETIME 作为石斑鱼。

SELECT
   SUM(Amount) AS MonthTotal,
   CAST(CAST(YEAR(DateCollected) AS VARCHAR(4)) 
     + '/' + CAST(MONTH(DateCollected) AS VARCHAR(2)) 
     + '/01' AS DATETIME) AS PaymentMonth
FROM
   PaymentsReceived
GROUP BY
   CAST(CAST(YEAR(DateCollected) AS VARCHAR(4)) 
     + '/' + CAST(MONTH(DateCollected) AS VARCHAR(2)) + '/01' AS DATETIME)
于 2012-10-16T13:48:11.653 回答