如何获得一个月的前4个日期 [英] how to get top 4 date in a month

查看:82
本文介绍了如何获得一个月的前4个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,

我有一个月的记录,我想过滤该月前日期的前4个记录



谢谢n advance

Dear sir,

i have one month record, i want to filter top 4 record what ever date that month



thanks n advance

推荐答案

Try
select top (4) from table order by datecolumn desc


Try:
SELECT TOP 4 * FROM myTable WHERE DATEPART(year, @MATCHDATE)=DATEPART(year,[date]) AND DATEPART(month, @MATCHDATE)=DATEPART(month,[date]) ORDER BY [date]

WHERE条件仅允许您提供一个参数来选择日期-如果您的表格仅保留一个月,则您可以忽略它.

The WHERE condition just allows you to provide a parameter to select the date - if your table only holds one month, then you can omit it.


请尝试以下操作:

Try this instead:

SELECT TOP 4 * FROM [tablename] ORDER BY date_field des



如果这解决了您的问题,请标记为答案并投票5

问候,
爱德华



Please mark as answer and vote 5 if this solved your problem

Regards,
Eduard


这篇关于如何获得一个月的前4个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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