从“选择查询”中获取最大值记录 [英] Fetch Max Value record from Select Query

查看:120
本文介绍了从“选择查询”中获取最大值记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,



我的表结构如下:

col1 col2 col3

1 1 40

2 1 45

3 1 48

4 2 50

5 2 55



我想显示结果(最大col3):

col1 col2 col3

3 1 48
5 2 55



我必须通过'SELECT Statement'来做这件事。

提前致谢..

解决方案

试试这个.. :)



  演示
选择 max(Col3 ) as total,Col2 来自 [tbl_Demo] group by Col2)
选择 t otal,Col2,(选择 Col1 来自 [tbl_Demo] 其中 Col3 =总计) as ID 来自演示


Dear Sir,

I have a table structure like this:
col1 col2 col3
1 1 40
2 1 45
3 1 48
4 2 50
5 2 55

I want to show the Result Like(max of col3):
col1 col2 col3
3 1 48
5 2 55

I have to do this by 'SELECT Statement' only.
Thanks in advance..

解决方案

try this.. :)

with Demo as(
select max(Col3)as total,Col2 from [tbl_Demo] group by Col2)
select total,Col2,(select Col1 from [tbl_Demo] where Col3=total )as ID from Demo


这篇关于从“选择查询”中获取最大值记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆