SUM

Description

The SUM function returns the sum of the input column or expression values. (RedShift SQL Language Reference SUM Function)

Grammar Syntax

SUM ( [ DISTINCT | ALL ] expression )

This function is fully supported by Snowflake.

Sample Source Patterns

Input Code:

IN -> Redshift_01.sql
CREATE TABLE test_sum_function (
    col1 INT
 );

INSERT INTO test_sum_function
VALUES ('200'),
       ('20'),
       ('2'),
       ('2');

SELECT SUM(COL1), SUM(DISTINCT COL1), SUM(ALL COL1) FROM test_sum_function;

Output Code:

OUT -> Redshift_01.sql
CREATE TABLE test_sum_function (
    col1 INT
 )
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "redshift",  "convertedOn": "11/20/2024",  "domain": "test" }}';

INSERT INTO test_sum_function
VALUES ('200'),
       ('20'),
       ('2'),
       ('2');

SELECT SUM(COL1), SUM(DISTINCT COL1), SUM(ALL COL1) FROM
    test_sum_function;

There are no known issues.

Last updated