SQL 查询连接来自不同 fdb 数据库的表

标签 sql firebird jointable firebird2.1

我有 2 个 fdb 数据库 company.fdbtimeAtt.fdbcompany.fdb包含 staffDetail table

staffId       - 001
staffName     - Andy
staffStatus   - Active
timeAtt.fdb包含 staffAtt table
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'

但问题是,查询还显示非事件人员。所以我需要加入staffAtt来自 timeAtt.fdbstaffDetail来自 company.fdb仅显示处于事件状态的员工。我怎样才能做到这一点?

最佳答案

正如马克所指出的,你不能直接加入他们。但是您仍然可以使用 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

关于SQL 查询连接来自不同 fdb 数据库的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30320955/

相关文章:

firebird - 如何在firebird3中更改列类型

mysql - 如何构建具有多个连接表的数据库

neo4j - 如何在 cypher,NEO4J 中加入 2 个表

sql - 如何优化同一张表中的几个 "WHERE (Select .... ) = value"

sql - COALESCE 在 Where 子句中?

C#锁定SQL Server表的方法

firebird - 读取 firebird 数据库,rdbms 打开数据库时出现 i/o 错误

SQL 查询以查找比赛中的获胜者

linux - 32位linux上的32位firebird单文件数据库4GB大小限制吗?

grails - Grails中的自定义联接表