1
我有以下表:如何在子 - 子查詢引用表
Bradford_Score_Bands
BandNo InclusiveScore
------------------------
1 0
2 150
3 500
Bradford_Scores
ClockNo Dated Score
--------------------------------
2 30/10/14 123
99 30/10/14 3
2 29/10/14 101
99 29/10/14 8
僱員
ClockNo
--------------------
2
3
99
我的目標是根據自己的分數來制定出BandNo每個ClockNo今天和昨天
我能找到根據分值這樣正確的BandNo:
SELECT MIN(BandNo) FROM Bradford_Score_Bands WHERE InclusiveScore >= 123
我可以找到得分今天和昨天對每個人是這樣的:
SELECT DISTINCT EMP.ClockNo,
ISNULL((SELECT Score FROM Bradford_Scores BFT WHERE Dated = '2014-10-30' AND BFT.ClockNo = EMP.ClockNo), 0) As ScoreToday,
ISNULL((SELECT Score FROM Bradford_Scores BFT WHERE Dated = '2014-10-29' AND BFT.ClockNo = EMP.ClockNo), 0) As ScoreYesterday
FROM Employees EMP
但我不能似乎能夠將兩者結合起來。我覺得像這樣的工作:
SELECT DISTINCT EMP.ClockNo,
(SELECT MIN(BandNo) FROM Bradford_Score_Bands WHERE InclusiveScore >=
(SELECT Score FROM Bradford_Scores BFT1 WHERE Dated = '2014-10-30' AND BFT1.ClockNo = EMP.ClockNo)),
(SELECT MIN(BandNo) FROM Bradford_Score_Bands WHERE InclusiveScore >=
(SELECT Score FROM Bradford_Scores BFT2 WHERE Dated = '2014-10-29' AND BFT2.ClockNo = EMP.ClockNo))
FROM Employees EMP
但在我引用BFTX.ClockNo = EMP.ClockNo子查詢中的部分似乎是導致查詢失敗。我得到的幫助的普遍錯誤「數據記錄ManagerCurrency不是在記錄」
編輯: 我試圖在SQL Server此完全相同的查詢和它的作品,所以是有辦法重新寫這使它更普遍友好?
謝謝 - 這似乎在Pervasive和SQL Server上都有技巧。 – 2014-10-31 16:20:34