1.查询全表
select* from HS_APPROVE_DETAIL hh;
2.按时间取最新值得到查询结果
select YWLSH, max(EXECUTETIME) EXECUTETIME
from HS_APPROVE_DETAIL h
group by YWLSH;
3.排除空值得到查询结果
select *
from HS_APPROVE_DETAIL hh
where hh.executetransition is not null
and hh.executetransition <> ' ';
is not null是排除列为null值的, !=” 方式是判断列里面没有值
4.按照最新时间并查出结果
select h.*
from (select YWLSH, max(EXECUTETIME) EXECUTETIME
from HS_APPROVE_DETAIL h
group by YWLSH) hs
left join (select * from HS_APPROVE_DETAIL) h
on h.EXECUTETIME = hs.EXECUTETIME;
5.排除空值并按照最新时间并查出结果(具体表字段,可能会出现空值)
select h.*
from (select YWLSH, max(CREATETIME) CREATETIME
from HS_APPROVE_DETAIL h
group by YWLSH) hs
left join (select *
from HS_APPROVE_DETAIL hh
where hh.executetransition is not null
and hh.executetransition <> ' ') h
on h.CREATETIME = hs.createtime;
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/192843.html