通过MSSQL语句选择最高选择

通过MSSQL语句选择最高选择

本文介绍了通过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


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



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

08-22 20:44