这是我的查询。问题是我试图将派生的“LineNo”字段应用为 where 子句。下面的查询不起作用。简单地说,如果 LineHrs 列的值 > 0,它将将此派生列设置为给定值(例如,如果 Line5Hrs = 1.4,则行的“LineNo”=“第 5 行”)。我想使用这个值来搜索特定行的所有工作。
SELECT tblA.PROJECT_ID,
tblB.Line1Hrs,
tblB.Line2Hrs,
tblB.Line3Hrs,
tblB.Line4Hrs,
tblB.Line5Hrs,
tblB.Line6Hrs,
tblB.Line7Hrs,
"LineNo" =
CASE
WHen tblB.Line1Hrs > 0 Then 'Line1'
WHen tblB.Line2Hrs > 0 Then 'Line2'
WHen tblB.Line3Hrs > 0 Then 'Line3'
WHen tblB.Line4Hrs > 0 Then 'Line4'
WHen tblB.Line5Hrs > 0 Then 'Line5'
WHen tblB.Line6Hrs > 0 Then 'Line6'
WHen tblB.Line7Hrs > 0 Then 'Line7'
End
FROM tblA INNER JOIN tblB
ON tblA.blah = tblB.blah AND
tblA.blab = tblB.blab
WHERE LineNo = 'Line5'