informix嵌套查询问题,求助高手

hanxingwuqing 2008-02-14 04:40:32
SQL语句如下:
SELECT * FROM ( SELECT first 200 * from cts_trans order by mon_date DESC, mon_id DESC ) t order by
mon_date , mon_id

想实现从 cts_trans 表中,查出最后200条记录,然后将这200 条记录按升序排列。在sql server 下,将“first” 换成“top” 执行通过。在informix,进dbaccess命令行执行 ,报错如下(first 换成 top 也是一样):
201: A syntax error has occurred.

...全文
521 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dantin 2009-02-14
  • 打赏
  • 举报
回复
不会,帮忙顶起来
Mysap-gwg 2009-02-10
  • 打赏
  • 举报
回复
你可以写个SP,里面用
....
foreach
SELECT first 200 *
into: ls_goodcd,
...

from cts_trans order by mon_date DESC, mon_id DESC ;
insert into temp ss (....)
values(...)
end foreach
foreach

SELECT a
into: ls_goodcd,
ls_gdcdnm,
...
FROM ss order by mon_date , mon_id
end foreach

return ls_goodcd,ls_gdcdnm.......

........
狂风细雨 2009-02-02
  • 打赏
  • 举报
回复
要升序直接去掉括号里的DESC,不对吗?
狂风细雨 2009-02-02
  • 打赏
  • 举报
回复
的确first嵌套里面不能用,你这里又不需要嵌套查询,括号里不是已经降序排列了?括号外面你又变成升序排列了。
不折腾....
mosaic 2009-01-15
  • 打赏
  • 举报
回复
1楼的回复有问题。 在into temp的这种方式下是不支持first关键字的。反正使用first限制很多,比如不能用在视图的定义中,不能用在嵌套sql中,不能用在子查询中,不能用在insert的select子句中,不能用在将查询到的数据插入临时表的select中等等。

在informix里面要用一个sql来实现楼主的这个要求,没想出来这么搞。

humucun 2009-01-07
  • 打赏
  • 举报
回复
支持1楼的,informix不支持同一张嵌套查询,但不同表是可以的,比如:
select col1,col2 from table1 where col1 in (select col3 from table2 where...)
ywb1973 2008-03-05
  • 打赏
  • 举报
回复
informix不支持这种嵌套查询,你可以用临时表来实现
SELECT first 200 * from cts_trans order by mon_date DESC, mon_id DESC into temp xx;
SELECT * FROM xx order by mon_date , mon_id

1,195

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 Informix
社区管理员
  • Informix社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧