7

我有 2 个 fdb 数据库company.fdbtimeAtt.fdb

company.fdb包含staffDetail

staffId       - 001
staffName     - Andy
staffStatus   - Active

timeAtt.fdb包含staffAtt

staffId         - 001
staffName       - Andy
timeIn          - 07:30
timeOut         - 04:30
LI              - X (late in)
AB              - X (absent )
remarks         - Emergency leave

现在,我想查看我这样做的唯一缺席的员工

SELECT staffId,staffName,remarks FROM timeAtt.fdb WHERE AB = 'X'

但问题是,查询还显示非活动人员。所以我需要加入staffAttfromtimeAtt.fdbstaffDetailfromcompany.fdb以仅显示具有活动状态的员工。我怎样才能做到这一点?

4

2 回答 2

8

正如马克指出的那样,您不能直接加入他们。但是你仍然可以使用 DSQL 语句来获得你想要的东西。

execute blockexecute statement一起使用。这是一个示例。

execute block
returning (
   staffId integer,
   staffName varchar(100),
   remarks varchar(100)
   staffStatus varchar(10))
as
begin
   for SELECT staffId, staffName, remarks 
   FROM timeAtt 
   WHERE AB = 'X'
   into :staffId, :staffName, :remarks do begin

      execute statement 'select staffStatus from company where staffId = ' || staffId
      on external "your:connection:\string\and\db.fdb" as user FOO password BAR
      into :staffStatus;

      suspend;
   end
end
于 2015-05-27T14:14:29.547 回答
2

你不能。在 Firebird 中,您只能连接同一数据库文件中的表。Firebird 2.5 扩展EXECUTE STATEMENT为也在外部数据源上执行语句,但在不同数据库中拥有单个查询引用表是不可能的。

您有以下选择:

  1. 创建一个临时表,将需要的数据复制到该临时表中,然后加入该临时表,
  2. 将数据库合并为一个。
于 2015-05-19T10:30:17.447 回答