带别名的 sql 查询
我有一个包含此列的表---或者
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
Try this
据推测,
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 theselect
clause because they don't actually exist until the query is done running. So, you can't compare directly tonoofthingstoTake
, 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 ahaving
clause, not awhere
clause.(Note: You really should have posted your entire query)