SQL 查询帮助 - 使用 INTERBASE 的子查询

发布于 2024-11-16 00:28:20 字数 725 浏览 13 评论 0原文

我有以下查询,

SELECT *
FROM
              ( select distinct
                      r1.rep_code,
                      r1.contact_id,
                      c1.Name,
                      e1.year_num,
                      e1.period_num
                   from
                      entry e1
                         join rep r1 ON e1.rep_code = r1.rep_code
                            join contact c1 on r1.contact_id = c1.contact_id
                   where
                          e1.entry_type = 'SJOB'
                      and e1.age = 0 )

我在第 3 行不断收到错误,

Token unknown - line 3, char 15
select

请您提供建议,顺便说一句,我正在使用 interbase IBConsole

I have the following query

SELECT *
FROM
              ( select distinct
                      r1.rep_code,
                      r1.contact_id,
                      c1.Name,
                      e1.year_num,
                      e1.period_num
                   from
                      entry e1
                         join rep r1 ON e1.rep_code = r1.rep_code
                            join contact c1 on r1.contact_id = c1.contact_id
                   where
                          e1.entry_type = 'SJOB'
                      and e1.age = 0 )

I keep getting an error on line 3

Token unknown - line 3, char 15
select

can you please advice, by the way im using interbase IBConsole !!

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

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

发布评论

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

评论(5

显然,Interbase 不支持派生表 (SELECT FROM (SELECT) )。或者,至少是您正在使用的版本(我不能确定,我已经有一段时间没有使用 Interbase 了)。 Firebird 2.0 中添加了此功能。您在这里有两个选择:

  • 更改您的方法,以便不使用SELECT FROM (SELECT)(派生表)

    OR

  • < p>升级到 Firebird

如果您有自主权,那么您绝对应该选择选项#2。

顺便说一句,Firebird 不要求您为派生表声明别名,尽管如果您要将派生表与其他表/派生表连接起来,这最终是必要的

Apparently, Interbase does not support derived tables (SELECT FROM (SELECT)). Or, at least, the version you are using (I cannot be sure, it's been a while since I don't work with Interbase). This feature was added in Firebird 2.0. You have two options here:

  • Change your approach so that you don't use SELECT FROM (SELECT) (derived tables)

    OR

  • Upgrade to Firebird

If you have autonomy for that, you should definitively go with option #2.

BTW, Firebird does not require you to declare an alias for your derived table, although that will end up being necessary if you will have your derived table JOINED with other table(s)/derived table(s)

不疑不惑不回忆 2024-11-23 00:28:20

InterBase 不支持派生表。但它们对此查询没有任何好处,因此只需删除它即可:

              select distinct
                  r1.rep_code,
                  r1.contact_id,
                  c1.Name,
                  e1.year_num,
                  e1.period_num
               from
                  entry e1
                     join rep r1 ON e1.rep_code = r1.rep_code
                        join contact c1 on r1.contact_id = c1.contact_id
               where
                      e1.entry_type = 'SJOB'
                         and e1.age = 0 

...在这种情况下将为您提供与派生表相同的结果..

InterBase doesn't support derived tables. But they give you no benefit for this query, so just get rid of it:

              select distinct
                  r1.rep_code,
                  r1.contact_id,
                  c1.Name,
                  e1.year_num,
                  e1.period_num
               from
                  entry e1
                     join rep r1 ON e1.rep_code = r1.rep_code
                        join contact c1 on r1.contact_id = c1.contact_id
               where
                      e1.entry_type = 'SJOB'
                         and e1.age = 0 

...will give you the same results as a derived table would in this case..

眼角的笑意。 2024-11-23 00:28:20

您需要为子查询指定一个别名。

SELECT *
FROM
          ( select distinct
                  r1.rep_code,
                  r1.contact_id,
                  c1.Name,
                  e1.year_num,
                  e1.period_num
               from
                  entry e1
                     join rep r1 ON e1.rep_code = r1.rep_code
                        join contact c1 on r1.contact_id = c1.contact_id
               where
                      e1.entry_type = 'SJOB'
                  and e1.age = 0 ) AS tbl

You need to give the subquery an alias.

SELECT *
FROM
          ( select distinct
                  r1.rep_code,
                  r1.contact_id,
                  c1.Name,
                  e1.year_num,
                  e1.period_num
               from
                  entry e1
                     join rep r1 ON e1.rep_code = r1.rep_code
                        join contact c1 on r1.contact_id = c1.contact_id
               where
                      e1.entry_type = 'SJOB'
                  and e1.age = 0 ) AS tbl
抚你发端 2024-11-23 00:28:20
SELECT *
FROM
              ( select distinct
                      r1.rep_code,
                      r1.contact_id,
                      c1.Name,
                      e1.year_num,
                      e1.period_num
                   from
                      entry e1
                         join rep r1 ON e1.rep_code = r1.rep_code
                            join contact c1 on r1.contact_id = c1.contact_id
                   where
                          e1.entry_type = 'SJOB'
                      and e1.age = 0 ) AS TABLE1
SELECT *
FROM
              ( select distinct
                      r1.rep_code,
                      r1.contact_id,
                      c1.Name,
                      e1.year_num,
                      e1.period_num
                   from
                      entry e1
                         join rep r1 ON e1.rep_code = r1.rep_code
                            join contact c1 on r1.contact_id = c1.contact_id
                   where
                          e1.entry_type = 'SJOB'
                      and e1.age = 0 ) AS TABLE1
想你的星星会说话 2024-11-23 00:28:20

我收到这个错误:

#
1248 - 每个派生表必须有自己的别名

请尝试以下操作:

SELECT *
FROM
              ( select distinct
                      r1.rep_code,
                      r1.contact_id,
                      c1.Name,
                      e1.year_num,
                      e1.period_num
                   from
                      entry e1
                         join rep r1 ON e1.rep_code = r1.rep_code
                            join contact c1 on r1.contact_id = c1.contact_id
                   where
                          e1.entry_type = 'SJOB'
                      and e1.age = 0 ) AS entries

I got this error:

#
1248 - Every derived table must have its own alias

try something like:

SELECT *
FROM
              ( select distinct
                      r1.rep_code,
                      r1.contact_id,
                      c1.Name,
                      e1.year_num,
                      e1.period_num
                   from
                      entry e1
                         join rep r1 ON e1.rep_code = r1.rep_code
                            join contact c1 on r1.contact_id = c1.contact_id
                   where
                          e1.entry_type = 'SJOB'
                      and e1.age = 0 ) AS entries
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文