通过MSSQL语句选择最高选择 [英] Selecting Highest Selecting by MSSQL Statement

查看:76
本文介绍了通过MSSQL语句选择最高选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写mssql查询,从今天开始的两周内从价格栏中选择最高价格。



谢谢

I would like to write mssql query for selecting highest price from Price Column during two weeks starting from today.

Thanks

推荐答案

Hi ttds,

Your Query is not so clear .
/*
Assuming Table name as tblPrice and Date Column to be colDate
*/

1) Incase if you want output as maximum price within 2 weeks

Select max(Price) from tblPrice
where colDate between Dateadd (dd,-14,getdate()) and getdate();

2) In case you want datewise max price as output

Select max(Price),colDate from tblPrice
where colDate between Dateadd (dd,-14,getdate()) and getdate()
group by colDate


类似于:

Something like:
SELECT MAX(Price) FROM MyTable WHERE MyDate > DATE_SUB(CURDATE(), INTERVAL 2 WEEK)






SELECT MAX(价格)FROM Price_Table WHATE PRICE_DT在DATEADD(DAY,-14,SYSDATETIME())和SYSDATETIME()之间
Hi,

SELECT MAX(Price) FROM Price_Table WHERE PRICE_DT Between DATEADD(DAY,-14,SYSDATETIME()) and SYSDATETIME()


这篇关于通过MSSQL语句选择最高选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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