拥有任何并拥有一切

发布于 2024-08-20 19:45:48 字数 822 浏览 10 评论 0原文

SQL Server 2005 是否支持带有 HAVINGANYEVERY

假设我有两个表:

Training(TrainingID, TrainingCloseDate) and
TrainingDetail(TrainingDetailID, TrainingID, LKClassCode, CompletionDate).

对于一个 TrainingIDTrainingDetail 中可以有多个具有不同 LKClassCode 的值。我需要找到至少有一个 TrainingDetailIDCompletionDate 在 2009 年 1 月 1 日到 2010 年 1 月 1 日之间的所有 TrainingID

当我尝试使用 HAVING ANY 时,出现错误:

Incorrect syntax near the keyword 'ANY'.

如果不支持,您能否建议替代方案?

如果我需要查找“至少有一个 TrainingDetailID”且 CompletionDate 介于 1/1/2009 和 1/ 之间的所有 TrainingID,该怎么办? 1/2010 或 TrainingCloseDate = '5/5/2009' '?

Does SQL Server 2005 support ANY or EVERY with HAVING?

Suppose I have two tables:

Training(TrainingID, TrainingCloseDate) and
TrainingDetail(TrainingDetailID, TrainingID, LKClassCode, CompletionDate).

For one TrainingID, there can be multiple values in TrainingDetail with different LKClassCode. I need to find all the TrainingID's which have at least one TrainingDetailID with CompletionDate between 1/1/2009 and 1/1/2010.

When I tried with HAVING ANY, I got an error:

Incorrect syntax near the keyword 'ANY'.

If it is not supported, could you please suggest an alternative?

What if I need to find all the TrainingID's which have 'at least one TrainingDetailID with CompletionDate between 1/1/2009 and 1/1/2010 or the TrainingCloseDate = '5/5/2009' '?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

煮茶煮酒煮时光 2024-08-27 19:45:48

我需要找到至少有一个 TrainingDetailIDCompletionDate 介于 1/1/2009 和 1/ 之间的所有 TrainingID 1/2010。

SELECT TrainingID
FROM TrainingDetail
WHERE CompletionDate BETWEEN date1 AND date2

您可能需要将日期转换为正确的格式(时间戳?)。

如果我需要查找“至少有一个 TrainingDetailID”且 CompletionDate 在 2009 年 1 月 1 日之间的所有 TrainingID,该怎么办和 1/1/2010 或 TrainingCloseDate = '5/5/2009' '?

SELECT TD.TrainingID
FROM TrainingDetail TD
  JOIN Training T ON T.TrainingID = TD.TrainingID
WHERE (CompletionDate BETWEEN date1 AND date2) OR TrainingCloseDate = '5/5/2009'

I need to find all the TrainingID's which have at least one TrainingDetailID with CompletionDate between 1/1/2009 and 1/1/2010.

SELECT TrainingID
FROM TrainingDetail
WHERE CompletionDate BETWEEN date1 AND date2

You might need to convert dates to proper format (timestamp?).

What if I need to find all the TrainingID's which have 'at least one TrainingDetailID with CompletionDate between 1/1/2009 and 1/1/2010 or the TrainingCloseDate = '5/5/2009' '?

SELECT TD.TrainingID
FROM TrainingDetail TD
  JOIN Training T ON T.TrainingID = TD.TrainingID
WHERE (CompletionDate BETWEEN date1 AND date2) OR TrainingCloseDate = '5/5/2009'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文