关于Oracle的一个查询问题

来源:百度知道 编辑:UC知道 时间:2024/06/11 22:45:19
select * from tb_bmxx_ssswname t,tb_bmxx_sssw tb

where tb.stationid in (select distinct t.stationId from tb_bmxx_ssswname t) and tb.stationid=t.stationid
and tb.time in (SELECT MAX(a.time) AS Expr1 FROM tb_bmxx_sssw a GROUP BY a.stationid)

order by tb.time desc
这句与句需要查出tb_bmxx_sssw表中的数据,条件是tb_bmxx_ssswname表中同ID的数据插入时间为最新,和tb_bmxx_sssw表中的ID不重复。

现在有个问题,那个时间列的精度只有到分钟,在插入时会出现重复时间的情况,导致查询数据不符合要求,求那位大虾能在不改变数据精度的前提下,使数据符合要求。。。。。

拜谢啦=。。=|||
表结构
tb_bmxx_sssw
ID,STATIONID分类ID,TIME插入时间,WATER_LEVEL要显示的数据
tb_bmxx_ssswname
STATION分类名字,STATIONID分类ID
啊说错啦
这句与句需要查出tb_bmxx_ssswname表中的数据,条件是tb_bmxx_sssw表中同ID的数据插入时间为最新,和tb_bmxx_ssswname表中的ID不重复。

你的tb_bmxx_sssw 表中的ID是自增长列不??
还有tb_bmxx_sssw 表中time 的精度到秒了没有!!如果没有精度到秒肯定会有重复的那就没法根据时间来判断最新的了!
如果是tb_bmxx_sssw 表中的ID是自增长列 可以这样查

select * from tb_bmxx_ssswname t,tb_bmxx_sssw tb
where tb.stationid=t.stationid and tb.id in
(select max(a.id) ,a.STATIONID from tb_bmxx_sssw a group by a.STATIONID)

---------------------------------
tb.stationid in (select distinct t.stationId from tb_bmxx_ssswname t)
这句什么意思???你在给自己找麻烦吗??

先占个位