Interbase SQL 语句不起作用

发布于 2024-12-08 05:13:45 字数 749 浏览 0 评论 0原文

我正在尝试为 Interbase 编写 SQL 语句。

这个SQL有什么问题吗?

md_master (trm) = 主表 cd_Med (cdt) = 详细信息表

SELECT trm.seq_no, trm.recipient_id, trm.payee_fullname, trm.payee_address1, trm.payee_address2, trm.payee_address3, trm.payee_address_city, trm.payee_address_state, trm.recip_zip, trm.recip_zip_4, trm.recip_zip_4_2, trm.check_no, trm.check_date, trm.check_amount,
cdt.com_ss_source_sys, cdt.cd_pay_date, cdt.com_set_amount,
bnk.name, bnk.address, bnk.transit_routing,
act.acct_no
FROM md_master trm, cd_med cdt, accounts act, banks bnk
join cd_med on cdt.master_id = trm.id
join accounts on act.acct_id = trm.account_tag
join banks on bnk.bank_id = act.bank_id
ORDER BY cdt.master_id

我没有收到错误消息,计算机只是继续运行并挂起。

I am trying to write a SQL Statement for Interbase.

Whats wrong with this SQL?

md_master (trm) = Master Table
cd_Med (cdt) = Detail table

SELECT trm.seq_no, trm.recipient_id, trm.payee_fullname, trm.payee_address1, trm.payee_address2, trm.payee_address3, trm.payee_address_city, trm.payee_address_state, trm.recip_zip, trm.recip_zip_4, trm.recip_zip_4_2, trm.check_no, trm.check_date, trm.check_amount,
cdt.com_ss_source_sys, cdt.cd_pay_date, cdt.com_set_amount,
bnk.name, bnk.address, bnk.transit_routing,
act.acct_no
FROM md_master trm, cd_med cdt, accounts act, banks bnk
join cd_med on cdt.master_id = trm.id
join accounts on act.acct_id = trm.account_tag
join banks on bnk.bank_id = act.bank_id
ORDER BY cdt.master_id

I don't get an error, the computer just keeps crunching away and hangs.

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

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

发布评论

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

评论(3

青春有你 2024-12-15 05:13:45

我具体不了解 Interbase,但是 FROM 子句似乎有点奇怪(也许只是我不熟悉的一些语法)。这有帮助吗?

...
FROM md_master trm
join cd_med cdt on cdt.master_id = trm.id
join accounts act on act.acct_id = trm.account_tag
join banks bnk on bnk.bank_id = act.bank_id

顺便说一句,您没有 WHERE 子句,因此如果这些表中的任何一个很大,我不会对它需要很长时间来运行感到过于惊讶。

I don't know about Interbase specifically, but that FROM clause seems a little strange (perhaps just some syntax I'm not familiar with though). Does this help?

...
FROM md_master trm
join cd_med cdt on cdt.master_id = trm.id
join accounts act on act.acct_id = trm.account_tag
join banks bnk on bnk.bank_id = act.bank_id

By the way, you have no WHERE clause so if any of these tables is large, I wouldn't be overly surprised that it takes a long time to run.

总攻大人 2024-12-15 05:13:45

您已经被一种名为隐式联接语法的反模式所困扰。

SELECT * FROM table_with_a_1000rows, othertable_with_a_1000rows

将对两个表进行交叉联接,选择输出中的 100 万行。

您正在做:

FROM md_master trm, cd_med cdt, accounts act, banks bnk

对 4 个表进行交叉联接(之后与普通联接相结合),这可以轻松生成数十亿行。
难怪 interbase 会挂起;它会一直工作到时间结束,以生成比宇宙中原子还要多的行。

解决方案
切勿在 FROM 子句后使用 ,,这是隐式连接,而且是邪恶的。
仅使用显式连接,如下所示:

SELECT 
  trm.seq_no, trm.recipient_id, trm.payee_fullname, trm.payee_address1
  , trm.payee_address2, trm.payee_address3, trm.payee_address_city
  , trm.payee_address_state, trm.recip_zip, trm.recip_zip_4, trm.recip_zip_4_2
  , trm.check_no, trm.check_date, trm.check_amount
  , cdt.com_ss_source_sys, cdt.cd_pay_date, cdt.com_set_amount
  , bnk.name, bnk.address, bnk.transit_routing
  , act.acct_no
FROM md_master trm
join cd_med on cdt.master_id = trm.id
join accounts on act.acct_id = trm.account_tag
join banks on bnk.bank_id = act.bank_id
ORDER BY cdt.master_id

You have been bitten by an anti-pattern called implicit join syntax

SELECT * FROM table_with_a_1000rows, othertable_with_a_1000rows

Will do a cross-join on both tables selecting 1 million rows in the output.

You are doing:

FROM md_master trm, cd_med cdt, accounts act, banks bnk

A cross join on 4 tables (combined with normal joins afterwards), which could easily generate many billions of rows.
No wonder interbase hangs; it is working until the end of time to generate more rows then there are atoms in the universe.

The solution
Never use , after the FROM clause, that is an implicit join and it is evil.
Only use explicit joins, like so:

SELECT 
  trm.seq_no, trm.recipient_id, trm.payee_fullname, trm.payee_address1
  , trm.payee_address2, trm.payee_address3, trm.payee_address_city
  , trm.payee_address_state, trm.recip_zip, trm.recip_zip_4, trm.recip_zip_4_2
  , trm.check_no, trm.check_date, trm.check_amount
  , cdt.com_ss_source_sys, cdt.cd_pay_date, cdt.com_set_amount
  , bnk.name, bnk.address, bnk.transit_routing
  , act.acct_no
FROM md_master trm
join cd_med on cdt.master_id = trm.id
join accounts on act.acct_id = trm.account_tag
join banks on bnk.bank_id = act.bank_id
ORDER BY cdt.master_id
叹倦 2024-12-15 05:13:45

错误在于 from 子句。您使用的一半是逗号分隔的表,在 where 子句中没有关系,一半是连接。

只需使用连接,一切都应该正常工作

The error lie in the from clause. You are using half with comma separated tables without a relation in where clause and half with joins.

Just use joins and all should work fine

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