请问一下oracle 里查询表的问题,高手请进!

来源:百度知道 编辑:UC知道 时间:2024/09/22 07:02:31
请问一下oracle 里查询表ST,字段stcdt(id)分别是1-6、字段ymdhm(时间)要大于某个时间
stcdt=1、2、3、4、5、6
ymdhm>2008-8-1 12:00:00

SQLSERVER里是这样:
select top 100 stcdt,ymdhm,zr from ST where ymdhm>'2008-8-1 12:00:00' and stcdt=1 and stcdt=2 and stcdt=3 order by ymdhm asc

查询oracle怎么实现?
谢谢

select * from (
select stcdt,ymdhm,zr from ST
where ymdhm>to_date('yyyy-m-dd hh24:mi:ss','2008-8-1 12:00:00')
and stcdt in (1,2,3)
order by ymdhm asc )
where rownum <=100;

stcdt=1 and stcdt=2 and stcdt=3
把你的这个改了~!
这能查出来数据吗?
同时一个字段要等于3个值?
上面的语句应该是你要的~!

select top 100 stcdt,ymdhm,zr from ST where ymdhm>to_date('2008-8-1 12:00:00','yyyy-mm-dd hh:mi:ss') and stcdt=1 and stcdt=2 and stcdt=3 order by ymdhm

主要是to_date函数的一个应用,to_date('2008-8-1 12:00:00','yyyy-mm-dd hh:mi:ss')

--实现TOP 100的方法
select stcdt,ymdhm,zr from
(
select rownum r, stcdt,ymdhm,zr
from ST
where ymdhm>to_date('yyyy-m-d hh24:mi:ss','2008-8-1 12:00:00')
and stcdt=1 and stcdt=2 and stcdt=3
--乖乖,这个条件能查出数据来
order by ymdhm asc
)
where r<=100