带别名的 sql 查询

发布于 2024-09-03 18:49:41 字数 595 浏览 5 评论 0原文

我有一个包含此列的表---或者

orgid ispaid validity      noofthingstoTake

1      yes    2010-06-05      20
2      yes    2010-06-09       7

我使用了这个查询(连接另外两个表):

select distinct B.RequirementID,A.OrganizationID 
from 
Organization A,RequirementsDetailsforOrganization B,validityorgdet F
where A.OrganizationID=B.OrganizationID and F.orgid=A.OrganizationID and
 F.ispaid=1 and F.validity>=GETDATE() and 

  F.noofthingstoTake> ?? 

但我不知道如何检查这里的(noofthingtaken)。它不应超过 20。我将此查询从我的代码隐藏页面传递到 Sql。如何让查询执行来检查它不应该超过 noofthingtaken

请帮助我......???

i have a table with this columns--- Or

orgid ispaid validity      noofthingstoTake

1      yes    2010-06-05      20
2      yes    2010-06-09       7

i have used this query(to join two more tableS):

select distinct B.RequirementID,A.OrganizationID 
from 
Organization A,RequirementsDetailsforOrganization B,validityorgdet F
where A.OrganizationID=B.OrganizationID and F.orgid=A.OrganizationID and
 F.ispaid=1 and F.validity>=GETDATE() and 

  F.noofthingstoTake> ?? 

but i dont know how to check the (noofthingstaken) over here. it should not exceed 20. im passing this query from my code behind page to the Sql. how to get the query excute to check it should not exceed the noofthingstaken

pls help me out....????

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

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

发布评论

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

评论(2

人海汹涌 2024-09-10 18:49:41

试试这个

select distinct B.RequirementID,A.OrganizationID from 
Organization A,RequirementsDetailsforOrganization B,validityorgdet F
where A.OrganizationID=B.OrganizationID and F.orgid=A.OrganizationID and
 F.ispaid=1 and F.validity>=GETDATE() and   F.noofthingstoTake <= 20

Try this

select distinct B.RequirementID,A.OrganizationID from 
Organization A,RequirementsDetailsforOrganization B,validityorgdet F
where A.OrganizationID=B.OrganizationID and F.orgid=A.OrganizationID and
 F.ispaid=1 and F.validity>=GETDATE() and   F.noofthingstoTake <= 20
ぃ弥猫深巷。 2024-09-10 18:49:41

据推测,noofthingstoTake 实际上是一个别名,而不是表中的列名。您不能在 select 子句之外使用列别名,因为在查询运行完成之前它们实际上并不存在。因此,您不能直接与 noofthingstoTake 进行比较,而必须引用该列来自的实际字段名称。如果是表达式,则使用整个表达式。请注意,如果它是聚合,则需要将其放入 having 子句中,而不是 where 子句中。

(注意:您确实应该发布整个查询)

Presumably noofthingstoTake is actually an alias and not a column name in your table. You can't use column aliases outside of the select clause because they don't actually exist until the query is done running. So, you can't compare directly to noofthingstoTake, but must instead refer to the actual field name that that column came from. If it's an expression, just use the entire expression. Note that if it's an aggregate, you'll need to put it in a having clause, not a where clause.

(Note: You really should have posted your entire query)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文