使用Order by with create view或在Interbase中插入

时间:2012-11-14 18:27:14

标签: sql firebird interbase

我在interbase中排序数据时遇到问题,我的时间戳是年,月,日等的单独列,所以我需要按顺序排序(尽管在这种情况下它甚至不能按顺序排序单场)。 由于某种原因,ORDER命令在与CREATE VIEW或INSERT INTO结合使用时会引发“令牌未知”错误。我在这里做了一个愚蠢的语法错误,还是我尝试使用ORDER命令的方式有一个更基本的问题?

CREATE VIEW HOURLY_AVES_SORT (MEASYEAR,MEASMONTH,MEASDAY,MEASHOUR,GH,GK,GDH,TA) as
SELECT
  HOURLY_AVES_ALL.MEASYEAR, HOURLY_AVES_ALL.MEASMONTH, HOURLY_AVES_ALL.MEASDAY,
  HOURLY_AVES_ALL.MEASHOUR, /*HOURLY_AVES.MEASMIN, HOURLY_AVES_ALL.MEASSECOND, */
  HOURLY_AVES_ALL.GH, HOURLY_AVES_ALL.GK, HOURLY_AVES_ALL.GDH, HOURLY_AVES_ALL.TA

FROM HOURLY_AVES

ORDER BY
   HOURLY_AVES_ALL.MEASYEAR, HOURLY_AVES_ALL.MEASMONTH, HOURLY_AVES_ALL.MEASDAY,
  HOURLY_AVES_ALL.MEASHOUR

尝试将数据复制到另一个表而不是视图中,会抛出相同的令牌未知错误,即:

INSERT INTO HOURLY_AVES_SORTED 
(MEASYEAR,MEASMONTH,MEASDAY,MEASHOUR,GH,GK,GDH,TA)

SELECT 
HOURLY_AVES_ALL.MEASYEAR, HOURLY_AVES_ALL.MEASMONTH, HOURLY_AVES_ALL.MEASDAY,
HOURLY_AVES_ALL.MEASHOUR, /*HOURLY_AVES.MEASMIN, HOURLY_AVES_ALL.MEASSECOND, */
HOURLY_AVES_ALL.GH, HOURLY_AVES_ALL.GK, HOURLY_AVES_ALL.GDH, HOURLY_AVES_ALL.TA

FROM HOURLY_AVES

ORDER BY
(MEASYEAR, MEASMONTH, MEASDAY,MEASHOUR, GH, GK,GH, TA) 

任何提示非常欢迎,Brian

2 个答案:

答案 0 :(得分:2)

Interbase不支持视图的ORDER BY语句中的SELECT子句。请参阅文档page 8-4 in the Data Definition Guide(从书签“使用视图” - >“创建视图” - >“使用SELECT语句”时,您可以找到该页面。)

答案 1 :(得分:1)

尝试使用列号:

CREATE VIEW HOURLY_AVES_SORT (MEASYEAR,MEASMONTH,MEASDAY,MEASHOUR,GH,GK,GDH,TA) as
SELECT
  h.MEASYEAR, h.MEASMONTH, h.MEASDAY, h.MEASHOUR, 
  h.GH, h.GK, h.GDH, h.TA

FROM 
  HOURLY_AVES h

ORDER BY
   1, 2, 3, 4