易截截图软件、单文件、免安装、纯绿色、仅160KB

关于获取SQL数据问题


select  example_a from example where time <=2009-11-01 and time >= 2009-01-01
在这个SQL语句里能否直接得到第一行example_a数据和最后一行example_a数据呢?
我现在的解决方案是TOP 1,然后在倒序TOP 1,这样的话影响效率。
加个自增列
用max(id)和min(id)呢?

只能这样吧.

解决方案是TOP 1,然后在倒序TOP 1

SQL code:
select example_a
from example t
where [time] <='2009-11-01' and [time] >= '2009-01-01'
and
(not exists(select 1 from example where [time] <='2009-11-01' and [time] >= '2009-01-01' and [time]>t.[time])
or
not exists(select 1 from example where [time] <='2009-11-01' and [time] >= '2009-01-01' and [time]<t.[time])
)


在time上建索引

引用
SQL codeselect  example_afrom example twhere[time] <='2009-11-01'and[time]>='2009-01-01'and
(notexists(select1from examplewhere[time] <='2009-11-01'and[time]>='2009-01-01'and[time]>t.[time])ornotexists?-

UP

引用
SQL codeselect  example_afrom example twhere[time] <='2009-11-01'and[time]>='2009-01-01'and
(notexists(select1from examplewhere[time] <='2009-11-01'and[time]>='2009-01-01'and[tim


相关问答:

csv文件转换成sql导入到数据库,没有数据为何?

执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......

数据窗口动态修改Sql - PowerBuilder / DataWindow

为了满足数据查询的速度问题,我将一张数据量大的学生表按年度分成多个表
students_2008, students_2009然后我又做了一个模板表students_template,模板表中的字段和students_2008, students_2009一样,只不过是一个 ......

sql语句的问题 - MS-SQL Server / 基础类

有2个表啊: 
表名:yh 
用户编码 用户名称  
001 a 
002 b 
003 c 
表名:ys 
用户编码 本期指数 抄表时间 
  001 ......

sql性能求助 - MS-SQL Server / 疑难问题

场景如下:
客户把备份好的数据库,发给我,我在本机还原后,运行写好的存储过程,比较快,并且在实施那边运行同样比较快。但是当实施在客户那边运行的时候速度就非常的慢,时间超出了程序的时间限制。远程在客户那 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号