SELECT ONE Row 与列上的 MAX() 值 [英] SELECT ONE Row with the MAX() value on a column

查看:22
本文介绍了SELECT ONE Row 与列上的 MAX() 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的每月通讯数据集:

I have a pretty simple dataset of monthly newsletters:

id  | Name          | PublishDate   | IsActive
1   |  Newsletter 1 | 10/15/2012    |     1
2   |  Newsletter 2 | 11/06/2012    |     1  
3   |  Newsletter 3 | 12/15/2012    |     0
4   |  Newsletter 4 | 1/19/2012     |     0

等等

PublishDate 是唯一的.

The PublishDate is unique.

结果(基于以上):

id  | Name          | PublishDate   | IsActive
2   |  Newsletter 2 | 11/06/2012    |     1  

我想要的很简单.我只想要 IsActive 和 PublishDate = MAX(PublishDate) 的 1 份时事通讯.

What I want is pretty simple. I just want the 1 newsletter that IsActive and PublishDate = MAX(PublishDate).

推荐答案

select top 1 * from newsletters where IsActive = 1 order by PublishDate desc

这篇关于SELECT ONE Row 与列上的 MAX() 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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