如何从该 sql 查询中消除子查询?
我有一个应该可以工作的查询,但似乎我是糟糕的数据库技术的受害者。我需要在 Pervasive SQL 数据库上运行下面的查询。使用 Pervasive 的产品制造商告诉我他们使用的版本是 10,应该支持子查询,但我还不能运行一个简单的子查询。所以,我想知道是否可以重写以下查询以消除子查询:
SELECT
OuterTime.Employee,
OuterTime.Date,
OuterTime.Pay_ID,
OuterTime.Description,
OuterTime.Equipment,
OuterTime.JC_Cost_Code,
OuterTime.JC_Category,
OuterTime.Units,
(
SELECT
SUM(SubQueryTime.Units)
FROM
PRT_NEW__TIME AS SubQueryTime
WHERE
SubQueryTime.Employee = OuterTime.Employee
GROUP BY
SubQueryTime.Employee
) AS TotalHoursForEmp
FROM
PRT_NEW__TIME AS OuterTime
I have a query which should work, but it seems I am a victim of a poor database technology. I need to run the query below on a Pervasive SQL database. The manufacturer of the product using Pervasive tells me the version they are using is 10 which should support subqueries, but I have yet to be able to run even a simple subquery. So, I am wondering if the following query can be rewritten to eliminate the subquery:
SELECT
OuterTime.Employee,
OuterTime.Date,
OuterTime.Pay_ID,
OuterTime.Description,
OuterTime.Equipment,
OuterTime.JC_Cost_Code,
OuterTime.JC_Category,
OuterTime.Units,
(
SELECT
SUM(SubQueryTime.Units)
FROM
PRT_NEW__TIME AS SubQueryTime
WHERE
SubQueryTime.Employee = OuterTime.Employee
GROUP BY
SubQueryTime.Employee
) AS TotalHoursForEmp
FROM
PRT_NEW__TIME AS OuterTime
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在标准 SQL 中你可以做到这一点,尽管我具体不知道 PervasiveSQL...
In standard SQL you can do this, though I have no idea about PervasiveSQL specifically...
不是 Pervasive SQL 专家,但这行得通吗?不确定它是否实现了您的查询目标:
Not a Pervasive SQL guy, but would this work? Not sure it accomplishes your query goals: