0

What is the equivalent query for

SELECT *,SUM(total_request_count) AS total_calls  FROM API_REQUEST_SUMMARY

in DB2. It says * is invalid in db2 data explorer. After running this I got below error

An unexpected token "*" was found following "SELECT ". Expected tokens may include: "NULL".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.68.61

Any Idea to resolve this is much appreciated.

1

any not aggregated column must be included in GROUP BY

SELECT COL1, COL2 ,SUM(total_request_count) AS total_calls  FROM API_REQUEST_SUMMARY GROUP BY COL1, COL2

alternative if many columns for GROUP BY

SELECT T1.*, T2.total_calls FROM API_REQUEST_SUMMARY T1 LEFT JOIN
(SELECT GROUP_COLUMN, SUM(total_request_count) AS total_calls  FROM API_REQUEST_SUMMARY GROUP BY GROUP_COLUMN) T2 ON T1.GROUP_COLUMN = T2.GROUP_COLUMN

it is my work solution, may be other present as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.