INTERBASE 中一个关于SQL查询的问题!50分相送!

以下语句在SQLserver中可以通过:
select top 10 job_title from job
但在interbase变成无效,出错!
我的功能是要作排行榜!排行前100名,其余不显示!
但发现用interbase数据库即不能用!
是不是语法不一样,望指教!
在线等待!
---------------------------------------------------------------

要前100条记录可以用下面的。
select job_title from job rows 100;或select job_title from job rows 1 to 100;
你下面说的功能一样可以通过rows来完成。
rows的具体用法:
ROWS

 1<value>   
 2[TO <upper_value>]   
 3[BY <step_value>]   
 4[PERCENT][WITH TIES]   
 5• value is the total number of rows to return if used by itself   
 6  
 7• value is the starting row number to return if used with TO   
 8  
 9• value is the percent if used with PERCENT   
10  
11• upper_value is the last row or highest percent to return   
12  
13• If step_value = n, returns every nth row, or n percent rows   
14  
15• PERCENT causes all previous ROWS values to be interpreted as percents   
16  
17• WITH TIES returns additional duplicate rows when the last value in the ordered sequence is the same as values in subsequent rows of the result set; must be used in conjunction with ORDER BY   
18  
19The following examples reward the best performing sales people and terminate the least performing members of the sales team. The examples show how a Web developer, for example, could split the result set in half for display purposes.   
20  
21SELECT SALESMAN, SALES_DOLLARS, SALES_REGION   
22FROM SALESPEOPLE   
23ORDER BY SALES_DOLLARS DESC   
24ROWS 1 TO 50;   
25SELECT SALESMAN, SALES_DOLLARS, SALES_REGION   
26FROM SALESPEOPLE   
27ORDER BY SALES_DOLLARS DESC   
28ROWS 50 TO 100 WITH TIES;   
29  
30Reward the best 100 performing salesmen with a 15 percent bonus:   
31  
32UPDATE SALESPEOPLE   
33SET SALES_BONUS = 0.15 * SALES_DOLLARS   
34ORDER BY SALES_DOLLARS DESC   
35ROWS 100 WITH TIES;   
36  
37Eliminate the worst five percent of the sales force:   
38  
39DELETE FROM SALESPEOPLE   
40ORDER BY SALES_DOLLARS   
41ROWS 5 PERCENT WITH TIES;   
42  
43  
44\---------------------------------------------------------------   
45  
46ib6.5 后提供了 Rows 语法,它是你想要的语法;   
47FB1.01 也提供了 First 的语法,他于 ib6 兼容,也是开源免费使用项目。   
48\---------------------------------------------------------------   
49  
50用 fb 吧.   
51  
52select first 10 job_title   
53from job   
54order by emp_id;   
55  
56  
57select MyID, sum(ammount) as all_ammount   
58from MyTable   
59group by MyID   
60order by sum(ammount)   
61having sum(ammount) &gt; 100;   
62  
63  
64以上问题属interbase版本问题!6.5以后提供了更多的功能,要简化代码,请尽快升级吧!</step_value></upper_value></value>
Published At
Categories with 数据库类
Tagged with
comments powered by Disqus