Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL查询帮助-使用INTERBASE的子查询_Sql_Select_Firebird_Interbase - Fatal编程技术网

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

SQL查询帮助-使用INTERBASE的子查询,sql,select,firebird,interbase,Sql,Select,Firebird,Interbase,我有以下疑问 SELECT * FROM ( select distinct r1.rep_code, r1.contact_id, c1.Name, e1.year_num, e1.period_num from

我有以下疑问

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 )
我一直在第三行出错

Token unknown - line 3, char 15
select

你能给我一些建议吗,顺便说一句,我正在使用interbase IBMConsole

您需要给子查询一个别名

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
我得到了这个错误:

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
显然,Interbase从SELECT中选择。或者,至少,您正在使用的版本我不能确定,我已经有一段时间没有使用Interbase了。Firebird 2.0中添加了此功能。这里有两个选项:

更改方法,以便不使用“从选择派生表中选择”

升级到Firebird

如果你在这方面有自主权,你应该明确地选择第二个选项


顺便说一句,Firebird不要求您为派生表声明别名,尽管如果您要将派生表与其他表/派生表连接起来,则必须声明别名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 

…将为您提供与派生表相同的结果。

请为您的问题提供更具描述性的标题。请在标签中指定您正在使用的数据库。我在firebird中测试了您的查询,它可以工作。@OrhanCinar知道为什么它不能在我的机器上工作吗?@c11ada您的IB版本是什么?@OrhanCinar我如何找到我使用的版本?请格式化您的代码。。。如何格式化我的代码。。。Iv已经尝试过了,但是我仍然得到了一个未知令牌的错误-第3行,字符4SELECT@c11ada-您使用的是什么数据库?@Oded IBConsole是InterBase Console即使我在子查询中选择了*,我仍然会在第行收到一个错误3@Odedim 100%这些列存在于它们的表中,并且我拥有数据库的管理员权限
              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