我正在努力以正确的方式编写查询。虽然确实有用,但我发错了:
发现了一个新的声明,但它与前一个声明之间没有分隔符(在选择附近)
显然我仍然能够处理这个错误但#1。我不是特别喜欢&haffy'应对方法和#2。它导致php进一步尝试运行查询的问题。
来自Google Research,它表明错误可能是一个错误,但我不敢相信这一点。
我实际上在尝试做什么:
我有3张桌子:
Table P [Process_ID+, Process_Name, Risk_ID*]
Table V [Validation_ID, Process_ID+, Validation_Date]
Table R [Risk_ID*, Risk_TimePeriod]
计划是:
如下所示:
Process_ID | Process_Name | Validation_Date | Due_Date | Due_Days | Risk_Level
1 My_Process 2017-02-17 2017-07-17 -150 High
所以在这里;已通过将150(Risk_Level)添加到验证日期来创建Due_Date。
当前查询
Set @TimePeriod =
(Select r.Risk_TimePeriod
from processes_active p
inner join processes_risk_config r
on r.Risk_ID = p.Process_Risk
where p.Process_ID = 2);
Select p.Process_ID,
p.Process_Name,
v.Validation_Date,
Date_Add(v.Validation_Date, interval @TimePeriod Day) as Due_Date,
Datediff(Now(), Date_Add(v.Validation_Date, interval @TimePeriod Day)) as Due_Days,
r.Risk_Level
From processes_active p
left JOIN processes_validations v
on p.Process_ID = v.Validation_Process_ID
inner join processes_risk_config r
on r.Risk_ID = p.Process_Risk
Where p.Process_ID = 2
Order By v.Validation_Date Desc
我的第一个"选择"子句突出显示为红色。这是出现错误消息的位置。如果有人能指出我哪里出错我会非常感激!感谢
答案 0 :(得分:0)
原来我完全过分复杂了!
新工作查询:
选择
p.Process_ID,
p.Process_Name,
v.Validation_Date,
r.Risk_TimePeriod,
Date_Add(v.Validation_Date, interval r.Risk_TimePeriod Day) as Due_Date,
Datediff(Now(), Date_Add(v.Validation_Date, interval r.Risk_TimePeriod Day)) as Due_Days,
r.Risk_Level
From pdc_processes.processes_active p
left JOIN pdc_processes.processes_validations v
on p.Process_ID = v.Validation_Process_ID
inner join processes_risk_config r
on r.Risk_ID = p.Process_Risk
Where p.Process_ID = 2
Order By v.Validation_Date Desc