我一直在使用SQL一段时间这么新,但一直在快速流行。我有一个非常强烈的查询,我需要为报告创建 - 我在excel中使用它并使用IF语句并且完美地工作。
这就是我所拥有和需要的: 我有一个包含多个包含日期的列的表。
一个'Raving Fan Name'可能有多个日期。这些是可能性/例子:
RavingFan ID 1 = FU Date + Testimonial Date + Bonus Date
RavingFan ID 2 = Referral Date + Signed Date
RavingFan ID 3 = Testimonial Date
我需要从包含日期过滤器(滚动6个月)的每个列中提取数据我已阅读多个select select语句。这就是我所拥有的,但它告诉我,我需要一个存在 - 希望有人可以帮助!
SELECT
(SELECT
rf.Raving_Fan_ID,
rf.Raving_Fan_Name,
cr.Contact_Role_Name,
emp.Emp_Name,
rf.FU_Detail,
rf.FU_Date,
rf.FU_Point,
rf.Bonus_Date,
rf.Bonus_Point
FROM Raving_Fans AS rf
LEFT JOIN Employees AS emp ON rf.Emp_ID = emp.Emp_ID
LEFT JOIN Contact_Role AS cr ON rf.Contact_Role_ID = cr.Contact_Role_ID
WHERE rf.FU_Date BETWEEN DATEADD(day,-181,getdate()) AND DATEADD(day,0,getdate())
)
(SELECT
rf.Raving_Fan_ID,
rf.Raving_Fan_Name,
cr.Contact_Role_Name,
emp.Emp_Name,
rf.Test_Detail,
rf.Test_Date,
rf.Test_Point,
rf.Bonus_Date,
rf.Bonus_Point
FROM Raving_Fans AS rf
LEFT JOIN Employees AS emp ON rf.Emp_ID = emp.Emp_ID
LEFT JOIN Contact_Role AS cr ON rf.Contact_Role_ID = cr.Contact_Role_ID
WHERE rf.Test_Date BETWEEN DATEADD(day,-181,getdate()) AND DATEADD(day,0,getdate())
)
(SELECT
rf.Raving_Fan_ID,
rf.Raving_Fan_Name,
cr.Contact_Role_Name,
emp.Emp_Name,
rf.Ref_Detail,
rf.Ref_Date,
rf.Ref_Point,
rf.Signed_Date,
rf.Signed_Point,
rf.Bonus_Date,
rf.Bonus_Point
FROM Raving_Fans AS rf
LEFT JOIN Employees AS emp ON rf.Emp_ID = emp.Emp_ID
LEFT JOIN Contact_Role AS cr ON rf.Contact_Role_ID = cr.Contact_Role_ID
WHERE rf.Ref_Date BETWEEN DATEADD(day,-181,getdate()) AND DATEADD(day,0,getdate())
)
我很难绕过这个。有更简单的方法吗?任何帮助表示赞赏。
答案 0 :(得分:0)
这是如何完成的,如果你想从多个列中提取某些标准。
[HttpGet]
public XmlDocument GetXML([FromBody]string JsonString)
{
System.Xml.XmlDocument xmlDocument = Newtonsoft.Json.JsonConvert.DeserializeXmlNode(JsonString);