コード例 #1
0
        static string WindowFrameClauseStr(SqlWinFrame frame)
        {
            if (frame == null)
            {
                return("");
            }
            var grouping =
                frame.Grouping == WinFrameGrouping.Rows ? "ROWS" :
                frame.Grouping == WinFrameGrouping.Range ? "RANGE" :
                frame.Grouping == WinFrameGrouping.Groups ? "GROUPS" :
                throw new ArgumentException();

            string startEnd(SqlWindowFrameStartEnd x) =>
            x.Type == WinFrameStartEnd.UnboundedPreceding ? "UNBOUNDED PRECEDING" :
            x.Type == WinFrameStartEnd.OffsetPreceding ? $"{x.Offset} PRECEDING" :
            x.Type == WinFrameStartEnd.CurrentRow ? "CURRENT ROW" :
            x.Type == WinFrameStartEnd.OffsetFollowing ? $"{x.Offset} FOLLOWING" :
            x.Type == WinFrameStartEnd.UnboundedFollowing ? "UNBOUNDED FOLLOWING" :
            throw new ArgumentException();

            var ret = grouping;

            ret +=
                frame.End != null ? $" BETWEEN {startEnd(frame.Start)} AND {startEnd(frame.End)}" :
                startEnd(frame.Start);

            if (frame.Exclusion != null)
            {
                var ex =
                    frame.Exclusion == WinFrameExclusion.CurrentRow ? "CURRENT ROW" :
                    frame.Exclusion == WinFrameExclusion.Group ? "GROUP" :
                    frame.Exclusion == WinFrameExclusion.Ties ? "TIES" :
                    frame.Exclusion == WinFrameExclusion.NoOthers ? "NO OTHERS" :
                    throw new ArgumentException();

                ret += " EXCLUDE " + ex;
            }
            return(ret);
        }
コード例 #2
0
        static ISqlWindowFrameStartBetweenAble <TIn> FrameGrouping <TIn>(this ISqlWindowFrameAble <TIn> input, WinFrameGrouping grouping)
        {
            var newFrame = new SqlWinFrame(grouping, null, null, null);

            return(new SqlWindowBuilder <TIn>(input.Input, input, input.Current.SetFrame(newFrame)));
        }