2016-10-26 1 views
0

이 쿼리를 작성했으며 결과가 그룹화되지 않았습니다. 그들은 같은 표시됩니다쿼리 내 그룹 데이터

Facility | Posting Month | Account Type | Amount 
------------------------------------------------- 
Name  | July   | Debit Adj. | 100 
Name  | July   | Credit Adj. | -200 
Name  | July   | Debit Adj. | 150 
Name  | July   | Credit Adj. | -150 
------------------------------------------------- 

내가 얻기 위해 노력하고 결과는 직불 치에 대해 한 번 나타날 때까지 게시 한 달입니다. 신용 Adj. 유형 및 각 총 금액. 총 $ 250의 Debits 및 - $ 350의 크레딧. 도와 주셔서 감사합니다!

SELECT pw.Facility, DATENAME(mm, pw.[Posting Date]) AS [Posting Month], 
    lc.[Gl Account Type], sum(pw.[Tx Amt]) AS Amount 
FROM DBO.PaymentWOLedger AS pw 
    JOIN DBO.LedgerCodeTable AS lc 
     ON lc.[Description] = pw.[Tx Desc] 
WHERE lc.[Gl Account Type] = 'Credit Adjustment (Write Off)' OR 
     lc.[GlAccount Type] = 'Debit Adjustment (CWO)' 
GROUP BY pw.[Posting Date], pw.Facility, lc.[Gl Account Type] 
ORDER BY pw.Facility, pw.[Posting Date] 

답변

2

사용 Month 대신 Date 당신이 그것에 date/month/year 부분이 Group bypw.[Posting Date]을 사용했기 때문에 현재의 데이터가 각 date에 그룹화됩니다

GROUP BY DATENAME(mm, pw.[Posting Date]), pw.Facility, lc.[Gl Account Type] 
ORDER BY pw.Facility, DATENAME(mm, pw.[Posting Date]) 

& Order by

Group by인치

+0

굉장! 지금은 의미가 있습니다. 도와 주셔서 감사합니다! – Tosh