SQL Server 2012(代号:Denali)CTP 3的FIRST_VALUE和LAST_VALUE的实际用途是什么
随着 Denali 的 CTP 3 版本的推出,我们有了更多的分析功能,其中我对其中两个感兴趣:
a) First_Value
b) Last_Value
我了解 < code>FIRST_VALUE 根据分区和 order by 子句返回第一个值,而 Last_Value
根据分区和 order by 子句返回最后一个值。
但在什么实际情况下它们会有用呢?一个实时情况示例将帮助我理解这一点。
With Denali's CTP 3 release , we have more analytical functions out of which I am interested in two:
a) First_Value
b) Last_Value
I understood that FIRST_VALUE
returns first value based on partition and order by clause while Last_Value
returns last value based on partition and order by clause.
But in what practical situation they will be useful? A sample real time situation will help me understand this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些函数可以帮助您从结果集中获取其他信息,而无需使用复杂的自连接、派生表等。例如,假设您的表中有二十条论坛消息,并且您想知道谁发起了该线程,以及谁发布了该消息最后的回应。它们按日期/时间排序,因此虽然 MIN() & MAX() 可以帮助您识别第一个和第二个何时最后的帖子发生后,他们无法告诉您这些作者是谁,除非您出去以某种方式获得了附加信息。即使这可能很复杂 - 例如,如果您没有自然或人工键列(您可以加入身份列),您可能会想加入日期/时间值,这些值不能保证是唯一的...
These functions can help you get other information from the resultset without using complicated self-joins, derived tables, etc. For example, let's say you have twenty forum messages in a table, and you want to know who started the thread, and who posted the last response. They are ordered by date/time, so while MIN() & MAX() can help you identify when the first & last posts occurred, they can't tell you who those authors were unless you went out and got that additional information somehow. Even that can be complicated - if you don't have a natural or artificial key column for example (you could join on an identity column), you might be tempted to join on the date/time values, which are not guaranteed to be unique...