专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 其他数据库

如何查询一个表中最值和最值对应的时间

发布时间:2010-05-24 21:31:45 文章来源:www.iduyao.cn 采编人员:星星草
怎么查询一个表中最值和最值对应的时间
在表T1中
tag value date_time
"A" 5 "2011-02-04 11:12:52"
"A" 9 "2011-02-04 14:33:46"
"A" 1 "2011-03-22 08:55:05"
"B" 7 "2011-01-21 22:34:57"
"B" 4 "2011-04-11 04:25:43"

请问怎么才能用一条SQL查出每个tag的最大值和最大值对应的时间, 最小值和最小值对应的时间 ?

------解决方案--------------------



SELECT * from tth a where not exists(select 1 from tth where a.tag=tag and a.value>value)
or
not exists(select 1 from tth where a.tag=tag and a.value<value)
------解决方案--------------------
SQL code
select * from t1 t
where not exists (select 1 from t1 where tag=t.tag and value<t.value)
unoin all
select * from t1 t
where not exists (select 1 from t1 where tag=t.tag and value>t.value)
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: