0
我有這個查詢返回正確的數據,但我想過濾它。通過唯一ID和將來最早的日期過濾SQL查詢
SELECT TOP (100) PERCENT dbo.Reg_Master.id, dbo.Cart_Programs.cartid, dbo.Reg_Master.F_ID, dbo.BlockPeriod.profileid, dbo.Reg_Master.FirstName,
dbo.Reg_Master.LastName, dbo.BlockPeriod.startdate, dbo.Cart_Programs.blockid
FROM dbo.Cart_Programs LEFT OUTER JOIN
dbo.Reg_Master ON dbo.Cart_Programs.cartid = dbo.Reg_Master.cartid LEFT OUTER JOIN
dbo.BlockPeriod ON dbo.Cart_Programs.blockid = dbo.BlockPeriod.id
WHERE (dbo.BlockPeriod.profileid = xxx) AND (dbo.Reg_Master.F_ID = xxxx)
ORDER BY dbo.BlockPeriod.startdate
對於每個dbo.Reg_Master.id
,我想只返回最早dbo.BlockPeriod.startdate
(即今天或更高版本 - 換句話說,忽略了已經通過日期)每個dbo.Reg_Master.id
,我似乎無法得到它正確格式化。
感謝您的幫助,但在這個例子。它根本不會過濾結果,所有記錄的startdate值都爲NULL。任何其他想法? – 2012-01-27 05:02:59
@resonantmedia - 我的不好,讓我編輯sql – 2012-01-27 05:04:29
@resonantmedia再試一次我已經更新了帖子+ sql – 2012-01-27 05:23:42