I have a query that returns data somewhat like this:
REF01 10 50 1
REF01 10 50 1
REF01 20 40 1
REF01 20 40 1
REF01 30 30 2
REF02 40 20 1
REF02 50 10 2
REF02 50 10 2
And I need it to return it like this:
REF01 60 120
REF02 90 30
To do so first I add a DISTINCT
(GROUP BY
with all the columns also seems to do the same) to remove the duplicates which returns it like this:
REF01 10 50 1
REF01 20 40 1
REF01 30 30 2
REF02 40 20 1
REF02 50 10 2
And then I need to add a SUM()
of that result without the removed duplicated ones being counted.
I have tried solutions like this one but I get an error with the FROM (SELECT ...)
and this one which does work except that one of the columns inside the subquery is the result of an operation (column_1-column_2-column_3
) which causes the error ORA-00972: identifier is too long
for exceeding the 30 characters maximum limit and trying to apply an alias with AS
in the subquery (inside the WITH SUBQUERY AS ( ... )
isn't working in MS Query from what I have tried.
Support for most SQL functions and such isn't the best on Microsoft Query.