사용 Group by DATEPART(month,DatePrinted)
2월 :
오전 뭔가를 기대했다. 이 달의 이름을해야하는 경우
Select DATEPART(month,DatePrinted) As MyMonth, COUNT(ReceiptNo) As CardPrinted
From mytble
Where ReceiptNo like '990%'
Group by DATEPART(month,DatePrinted)
, 다음 DATENAME()
함수를 사용
Select DATENAME(month,DatePrinted) As MyMonth, COUNT(ReceiptNo) As CardPrinted
From mytble
Where ReceiptNo like '990%'
Group by DATENAME(month,DatePrinted)
참고 : 당신이 올바른 결과를 얻을 년까지 그룹에 필요 할 수 있습니다. 그렇지 않으면 연도에 관계없이 비슷한 달 수를 얻게됩니다. 또한 COUNT(*)
에 의해 COUNT(ReceiptNo)
를 대체 할 수 DATEPART(mm,DatePrinted)
SELECT DATEPART(mm, DatePrinted) AS [Month], COUNT(ReceiptNo) As CardPrinted
FROM mytble
WHERE ReceiptNo LIKE '990%'
GROUP BY DATEPART(mm, DatePrinted)
에 당신이 특정 연도를 찾고있는 경우, WHERE
절 Year(DatePrinted) = yourYear
출처
2013-11-14 14:57:48
Kaf
GROUP BY DATEPART(yyyy, DatePrinted), DATEPART(mm, DatePrinted)
당신이 무엇을 어떻게해야합니까? – Ashalynd2012 년 1 월과 1 월 2013을 함께 또는 개별적으로 그룹화 하시겠습니까? –