【问题标题】:Issue Related to Combining SubQuery with Join in MS Access [duplicate]与在 MS Access 中将子查询与加入相结合的问题 [重复]
【发布时间】:2012-12-21 06:48:31
【问题描述】:

可能重复:
Isssue Related to Join in MS Access Database

我在 MS-Access 数据库文件中有一个数据库文件..

我有以下查询:

Select RGN.rgn_regionId,RGN.rgn_titleGuj AS Center,

(Select COUNT(*) from (select Distinct PRS.prs_personId From tb_personDepartment PD,tb_person PRS Where PD.pd_designationId = 1 And PD.pd_personId = PRS.prs_personId And PRS.prs_centerId = RGN.rgn_regionId And PRS.prs_attandanceStatus = 'Y')) As SKAt

From tb_person PRS,tb_personDepartment PD,tb_region RGN
Where PD.pd_personId = PRS.prs_personId
And PRS.prs_centerId = RGN.rgn_regionId
Group By RGN.rgn_regionId,RGN.rgn_titleGuj

表结构如下

select * from tb_person where prs_personId in (3)
--prs_personId   prs_uniqId prs_centerId prs_fName  prs_mName    prs_lName  prs_age   prs_addres   prs_areaId
-- 3                    1       1               abc     abc             abc         12      andn            2
--(1 row(s) affected)

    select * from tb_personDepartment where pd_personId in (3)

    --pd_personId          pd_mahotsavId pd_departmentId pd_designationId pd_MainSK
    ---------------------- ------------- --------------- ---------------- -----------
    --3                    1             41              1                1
    --3                    1             44              2                0
    --3                    1             104             1                1

--(3 row(s) affected)

select * from tb_personMahotsavDetail where pm_personId in (3)

--pm_personId   pm_mahotsavId pm_personStatus pm_sevaDaysH   pm_accommodationRequired pm_utaraPlace  
--------------- ------------- --------------- -------------- ------------------------ -------------  
--3                    1             SS              8           0                        NULL       

--(1 row(s) affected)

select * from tb_person where prs_personId in (3)
-- Single Record

select * from tb_personDepartment where pd_personId in (3)
-- Multiple Record With Same Person Id

select * from tb_personMahotsavDetail where pm_personId in (3)
-- Single Record

【问题讨论】:

  • 您是说这些表在 SQL Server 中并在 MS Access 中链接?这将对问题产生巨大影响!
  • 在 MS Access 中,您不能在内部查询中使用与在外部查询中使用相同的别名,您在两者中都将 tb_persons 别名为 PRS,等等。您使用的表已发布不包括prs_attandanceStatus,因此当字段/列名称与您的表不匹配时,我看不到此查询在 SQL Server 中的工作方式。

标签: sql database ms-access


【解决方案1】:

发生这种情况 当column name does not exist 或者它可能是misspelled

【讨论】:

  • 我在 SQL Server 中尝试过相同的查询。它可以正常工作。但在 MSAccess 中不起作用
  • 你能显示表结构吗,我会在最后尝试一下。
  • 您可以下载这个应用程序来生成脚本。 dbweigher.com/dbwscript.php
  • 我用表格结构编辑了我的帖子:
  • 我在您的查询中删除了Select COUNT(*) from,它运行了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-01
  • 1970-01-01
相关资源
最近更新 更多