我正在使用以下代码从 SQL 表中检索列 -
MAX(CASE WHEN bd.DayText = 'Monday' and bd.BookingDuration = 3 and CONVERT(time(0), bd.StartTime) < CONVERT(time(0), '12:00:00') AND bd.NoOfHOurs < 5.5 and s.PrimarySchool = 1 THEN bd.ID ELSE NULL END) "MondayHourlyAM",
MAX(CASE WHEN bd.DayText = 'Monday' and bd.BookingDuration = 3 and CONVERT(time(0), bd.StartTime) < CONVERT(time(0), '12:00:00') AND bd.NoOfHOurs < 5.5 and s.PrimarySchool = 1 THEN s.SchoolName ELSE NULL END) "MondayHourlyAMSchoolName",
MAX(CASE WHEN bd.DayText = 'Monday' and bd.BookingDuration = 3 and CONVERT(time(0), bd.StartTime) < CONVERT(time(0), '12:00:00') AND bd.NoOfHOurs < 5.5 and s.PrimarySchool = 1 THEN REPLACE(REPLACE(LTRIM(RIGHT(CONVERT(VARCHAR, bd.StartTime, 100), 7)) + '-' + LTRIM(RIGHT(CONVERT(VARCHAR(20), bd.EndTime, 100), 7)), 'AM',''), 'PM', '') ELSE NULL END) "MondayHourlyAMTimes",
MAX(CASE WHEN bd.DayText = 'Monday' and bd.BookingDuration = 3 and CONVERT(time(0), bd.StartTime) < CONVERT(time(0), '12:00:00') AND bd.NoOfHOurs < 5.5 and s.PrimarySchool = 1 THEN bd.TotalChargeAmount ELSE NULL END) "MondayHourlyAMTotalChargeAmount",
MAX(CASE WHEN bd.DayText = 'Monday' and bd.BookingDuration = 3 and CONVERT(time(0), bd.StartTime) < CONVERT(time(0), '12:00:00') AND bd.NoOfHOurs < 5.5 and s.PrimarySchool = 1 THEN bd.TotalPayAmount ELSE NULL END) "MondayHourlyAMTotalPayAmount",
MAX(CASE WHEN bd.DayText = 'Monday' and bd.BookingDuration = 3 and CONVERT(time(0), bd.StartTime) < CONVERT(time(0), '12:00:00') AND bd.NoOfHOurs < 5.5 and s.PrimarySchool = 1 THEN bd.BandBookedAt ELSE NULL END) "MondayHourlyAMBandBookedAt",
MIN(CASE WHEN bd.DayText = 'Monday' and bd.BookingDuration = 3 and CONVERT(time(0), bd.StartTime) < CONVERT(time(0), '12:00:00') AND bd.NoOfHOurs < 5.5 and s.PrimarySchool = 1 THEN bd.ID ELSE NULL END) "MondayHourlyAM2",
MIN(CASE WHEN bd.DayText = 'Monday' and bd.BookingDuration = 3 and CONVERT(time(0), bd.StartTime) < CONVERT(time(0), '12:00:00') AND bd.NoOfHOurs < 5.5 and s.PrimarySchool = 1 THEN s.SchoolName ELSE NULL END) "MondayHourlyAM2SchoolName",
MIN(CASE WHEN bd.DayText = 'Monday' and bd.BookingDuration = 3 and CONVERT(time(0), bd.StartTime) < CONVERT(time(0), '12:00:00') AND bd.NoOfHOurs < 5.5 and s.PrimarySchool = 1 THEN REPLACE(REPLACE(LTRIM(RIGHT(CONVERT(VARCHAR, bd.StartTime, 100), 7)) + '-' + LTRIM(RIGHT(CONVERT(VARCHAR(20), bd.EndTime, 100), 7)), 'AM',''), 'PM', '') ELSE NULL END) "MondayHourlyAM2Times",
MIN(CASE WHEN bd.DayText = 'Monday' and bd.BookingDuration = 3 and CONVERT(time(0), bd.StartTime) < CONVERT(time(0), '12:00:00') AND bd.NoOfHOurs < 5.5 and s.PrimarySchool = 1 THEN bd.TotalChargeAmount ELSE NULL END) "MondayHourlyAM2TotalChargeAmount",
MIN(CASE WHEN bd.DayText = 'Monday' and bd.BookingDuration = 3 and CONVERT(time(0), bd.StartTime) < CONVERT(time(0), '12:00:00') AND bd.NoOfHOurs < 5.5 and s.PrimarySchool = 1 THEN bd.TotalPayAmount ELSE NULL END) "MondayHourlyAM2TotalPayAmount",
MIN(CASE WHEN bd.DayText = 'Monday' and bd.BookingDuration = 3 and CONVERT(time(0), bd.StartTime) < CONVERT(time(0), '12:00:00') AND bd.NoOfHOurs < 5.5 and s.PrimarySchool = 1 THEN bd.BandBookedAt ELSE NULL END) "MondayHourlyAM2BandBookedAt",
当此代码运行时,我得到了 2 个预订,但返回的收费/支付费率适用于另一个预订。IE -
应该是预订 1- 收费 20 英镑,支付 10 英镑 预订 2- 收费 100 英镑,支付 50 英镑
但我收到预订 1 - 收费 100 英镑,支付 50 英镑 预订 2 - 收费 20 英镑,支付 10 英镑
我认为这是因为它在使用 MAX 和 MIN 时返回最高和最低。如何将返回到“HourlyAM”列的 MAX 和 MIN 值关联起来?
希望我解释得很好!谢谢