Skip to content

Commit

Permalink
add the sum function
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed May 22, 2024
1 parent d98bf99 commit 0ebad4b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dml_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ func CountDistinct(field string) string {
return strings.Join([]string{"COUNT(DISTINCT ", ")"}, field)
}

// Sum returns a SUM(field).
func Sum(field string) string {
return strings.Join([]string{"SUM(", ")"}, field)
}

// SelectSum appends the selected SUM(field) column in SELECT.
func (b *SelectBuilder) Sum(field string) *SelectBuilder {
return b.Select(Sum(b.db.GetDialect().Quote(field)))
}

// SelectCount appends the selected COUNT(field) column in SELECT.
func (b *SelectBuilder) SelectCount(field string) *SelectBuilder {
return b.Select(Count(b.db.GetDialect().Quote(field)))
Expand Down

0 comments on commit 0ebad4b

Please sign in to comment.