Вам придется отключиться, запустив сначала SELECT DISTINCT, а затем SUM () - ming.Вот так:
WITH
-- this is your input - don't use in real query
input(Sales,ID) AS (
SELECT 100,'a'
UNION ALL SELECT 100,'a'
UNION ALL SELECT 103.5,'c'
UNION ALL SELECT 105,'d'
UNION ALL SELECT 105,'d'
)
, -- < - replace this comma with "WITH", and start the real query here ...
uq (sales) AS (
SELECT DISTINCT
sales
FROM input
)
SELECT
SUM(sales)
FROM uq;
-- out SUM
-- out -------
-- out 308.5
-- out (1 row)
-- out
-- out Time: First fetch (1 row): 7.795 ms. All rows formatted: 7.826 ms
-- if ( 100 , 'a' ) is different from ( 100 , 'd' ), then it would be the below
WITH
-- this is your input - don't use in real query
input(Sales,ID) AS (
SELECT 100,'a'
UNION ALL SELECT 100,'a'
UNION ALL SELECT 103.5,'c'
UNION ALL SELECT 105,'d'
UNION ALL SELECT 105,'d'
)
, -- < - replace this comma with "WITH", and start the real query here ...
uq (sales,id) AS (
SELECT DISTINCT
sales
, id
FROM input
)
SELECT
SUM(sales)
FROM uq;
-- out SUM
-- out -------
-- out 308.5
-- out (1 row)
-- out
-- out Time: First fetch (1 row): 11.084 ms. All rows formatted: 11.117 ms