我有这些数据显示按年份分组的综合报告。我使用的是一个简单的
GROUP BY YEAR(BookingDate)
子句,一切正常。但我想要的是财政年度(1 April
至31 May
)而不是正常的日历年,那么我该怎么做呢?查询是..
SELECT
CONVERT(VARCHAR(25), c.Duration) AS Duration,
COALESCE(c.totalbookings, 0) AS totalbookings
FROM
(SELECT
YEAR(bookingdate) AS Duration,
COUNT(*) AS totalbookings
FROM
entbookings
WHERE BranchId=@Branchid
GROUP BY YEAR(bookingdate)
) AS c
LEFT OUTER JOIN
(SELECT
Duration,
SUM(totalitems) 'bkdqty'
FROM
[yrItemWISeTotalQty] (@BranchId) AS BkdQty
GROUP BY Duration
) AS d
ON c.Duration = d.Duration
被yrItemWISeTotalQty
定义为
CREATE FUNCTION [dbo].[yrItemWiseTotalQty]
(
@BrachId VARCHAR(MAX)
)
RETURNS TABLE AS
RETURN
SELECT
YEAR(EntBookings.BookingDate) AS Duration,
Sum(dbo.EntBookings.ItemCost) AS totalcost,
WHERE EntBookings.BranchId = @BrachId
GROUP BY Year(EntBookings.BookingDate)
同样,我使用GROUP BY Year()
它的工作效果很好,但我需要对其进行修改以采用 fy ie(4 月 1 日至 3 月 31 日)。我该怎么做?