我想知道是否有人可以将目光投向我正在尝试执行的查询,我想不出最好的方法。
我需要联系人表中的电子邮件、名字和姓氏以及热线表中的 HotlineID 和 Last Action。我想过滤存储在热线表中的“标志”列,只显示值为 1 的行。我通过这个查询实现了这一点:
select Email, FirstName, Surname, HotlineID, LastAction
from Hotline
left join contact on contact.companyid=hotline.CompanyID
and contact.ContactID=hotline.ContactID
where
hotline.Flag = 1
现在是我做不到的一点。在 Actions 表中有 3 列 'HotlineID' 'Comment' 'Date' Actions 表中的 HotlineID 链接到 HotlineID 中的 HotlineID。可以为每条热线添加多条评论,并在日期列中记录发布日期。
在第一个查询返回的行中,我想进一步过滤掉最大日期(最后记录的评论)比当前日期晚不到 48 小时的任何行。我在 Visual Studio 中使用“addwithvalue”来填充日期变量,但出于测试目的,我使用“2014-12-04”
我想出了这个,它失败了。但我不确定为什么?
Select Email, FirstName, Surname, hotline.HotlineID, LastAction
from Hotline
left join Contact on Contact.CompanyID=Hotline.CompanyID
and Contact.ContactID=Hotline.ContactID
inner join Actions on actions.HotlineID=hotline.HotlineID
where hotline.flag=1 and CONVERT(VARCHAR(25), Max(Date), 126) LIKE '2014-12-03%'
我正在使用 SQL Server。