窗口函数实现为SQL查询

时间:2015-11-19 13:08:25

标签: sql

我该如何实施:

AVG(X) OVER(PARTITION BY SegmentId) AS AvgX

在不使用AVG(X)的SQL查询中?

我只能支持sum,count,min,max,但不支持AVG

谢谢,

或者

2 个答案:

答案 0 :(得分:1)

从概念上讲,AVG(X)可以替换为SUM(X) / COUNT(X)

这个答案是否过于简单化了眼前的问题?

答案 1 :(得分:1)

这会返回相同的结果,但上下文不清楚。

using System;

using System.Windows.Forms;

public class numericTextbox : TextBox
{
    private const int WM_PASTE = 0x302;

    protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
    {
        string Value = this.Text;
        Value = Value.Remove(this.SelectionStart, this.SelectionLength);
        Value = Value.Insert(this.SelectionStart, e.KeyChar.ToString());
        e.Handled = Convert.ToBoolean(Value.LastIndexOf("-") > 0) || 
            !(char.IsControl(e.KeyChar) || 
              char.IsDigit(e.KeyChar) || 
            (e.KeyChar == '.' && !(this.Text.Contains(".")) || 
             e.KeyChar == '.' && this.SelectedText.Contains(".")) || 
            (e.KeyChar == '-' && this.SelectionStart == 0));

        base.OnKeyPress(e);

    }
    protected override void WndProc(ref System.Windows.Forms.Message m)
    {
        if (m.Msg == WM_PASTE)
        {
            string Value = this.Text;
            Value = Value.Remove(this.SelectionStart, this.SelectionLength);
            Value = Value.Insert(this.SelectionStart, Clipboard.GetText());
            decimal result = 0M;
            if (!(decimal.TryParse(Value, out result)))
            {
                return;
            }
        }
        base.WndProc(ref m);
    }
}