日期:2014-05-20  浏览次数:20512 次

这种sql查询怎么写 帮忙看看 谢谢~
new   high   low     volume   date
10         15       5       11           2007-1-2   11:08:01
14         25       1       8             2007-1-2   11:08:08
14         15       5       11           2007-1-2   11:08:10
......//有上百万条记录,我只要取每天的一些数据(按天来分组)

1:我要选出每天date值最小的那条记录上的new值,volume值,以及date值
2:我要选出每天date值最大的那条记录上的new值,volume值,以及date值
3:我要选出每天low值最小的那条记录上的low值,volume值,以及date值
4:我要选出每天high值最大的那条记录上的high值,volume值,以及date值

用一条语句实现实现上面的四个功能应该怎么写?(按天分组)

如果按月分组呢?


------解决方案--------------------
Select new, volume, date From TableName Where date In (Select Min(date) From TableName Group By Year(date)*10000 + Month(date) * 100 * Day(date))
------解决方案--------------------
Select new, volume, date From TableName Where date In (Select Min(date) From TableName Group By Year(date)*10000 + Month(date) * 100 * Day(date))
union
Select new, volume, date From TableName Where date In (Select max(date) From TableName Group By Year(date)*10000 + Month(date) * 100 * Day(date))
union
Select new, volume, date From TableName Where low In (Select min(low ) From TableName Group By Year(date)*10000 + Month(date) * 100 * Day(date))
union
Select new, volume, date From TableName Where high In (Select max(high ) From TableName Group By Year(date)*10000 + Month(date) * 100 * Day(date))
------解决方案--------------------
Group By Year(date)*10000 + Month(date) * 100 * Day(date))

Group By 我到现在还没研究明白