This content has been marked as final. Show 1 reply
Never write, let alone post, unformatted code.
Use whitespace, especially indentation, to show the extent of, and major parts of, sub-queries, CASE expressions, and complicated function calls.
When posting any formatted text on this site, type these 6 characters:
WITH mytable AS
(small letters only, inside curly brackets) before and after each section of formatted text. The code you posted whould be much more readable that way. For example:
( SELECT Col1 as someID
, sum ( case
when Col2 = something
) as val
) -- Summing all of the values of Col2 together to put a 2 in every row.
SELECT someFunction(someID) + ( select val
) -- I want the value from that column, doesn't matter which row it comes from
Remember the ABC's of GROUP BY: When you use a GROUP BY clause and/or an aggregate fucntion, then everything in the SELECT clause must be: (a) an <b>A</b>ggregate function, (b) one of the "group <b>B</b>y" expressions, (c) a <b>C</b>onstant, or (d) something that <b>D</b>epends entirely the above. (For example, if you "GROUP BY TRUNC(dt)", you can SELECT "TO_CHAR (TRUNC(dt), 'Mon-DD')"). You're using an aggregate function in sub-query my_table, but col1 is not an aggregate, a GROUP BY expression, a constant, or any combination of them. You probably meant to say "GROUP BY col1" at the end of that sub-query. Don't you need an END to the CASE expression? Every query needs a FROM clause. Your main query does not have one. Perhap the end of the code got cut off when you posted it, or perhaps the scalar sub-query at the end is supposed to be part of the main query. If you need help, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data (inside \