Skip to content

Commit 0ebad4b

Browse files
committed
add the sum function
1 parent d98bf99 commit 0ebad4b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

dml_select.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ func CountDistinct(field string) string {
137137
return strings.Join([]string{"COUNT(DISTINCT ", ")"}, field)
138138
}
139139

140+
// Sum returns a SUM(field).
141+
func Sum(field string) string {
142+
return strings.Join([]string{"SUM(", ")"}, field)
143+
}
144+
145+
// SelectSum appends the selected SUM(field) column in SELECT.
146+
func (b *SelectBuilder) Sum(field string) *SelectBuilder {
147+
return b.Select(Sum(b.db.GetDialect().Quote(field)))
148+
}
149+
140150
// SelectCount appends the selected COUNT(field) column in SELECT.
141151
func (b *SelectBuilder) SelectCount(field string) *SelectBuilder {
142152
return b.Select(Count(b.db.GetDialect().Quote(field)))

0 commit comments

Comments
 (0)